TransWikia.com

How does one-way data binding and MVC achieve loose coupling?

Software Engineering Asked by szeb on January 26, 2021

In my limited understanding, one-way data binding could happen like the following:

On the back-end, I have a Node backend server. In that, I have a layer that communicates with the database (Model). I have a controller that exposes URIs that the frontend server can connect to (Controller).

On the front-end, I have a React frontend server (View). The frontend-server sends requests to the URI-s exposed by the backend server.

If the frontend server wants to get data from the backend, it sends GET requests to the URIs exposed by the server (Controller), the server fetches the data (Model), and sends it to the frontend server (View).

If the frontend server wants to post some data so it will be stored on the server, it sends some POST requests to the server, which in turn handles it and saves the corresponding data.

I read that one-way data binding is basically an observer relationship between the view and the model. The view registers a callback with the model, and when something changes on the backend, the model will call the callback, and it will update things in the view. But why is this necessary, if you can just send and receive data using the URIs exposed by the controller? Is this forced by React? Obviously I’m wrong about something, but for me it seems like its counter-productive because it creates tight coupling without using the Controller, that would behave as an interface between View and the Model.

One Answer

But why is [one-way data binding] necessary, if you can just send and receive data using the URIs exposed by the controller?

It can be necessary if you need to provide live updates in your view of data that is modified by other sources.

For example, you are building an application to track how many available emergency-care beds are available in a particular geographical area. One of the views of that application is a dashboard that gets shown on a big screen.

That dashboard should show up-to-date information, but there is no human sitting next to it to refresh the screen and having it periodically poll the backend for updates might also be undesirable. That is where data binding and notifications from the Model are useful to refresh the dashboard exactly at the moment that the information changes.

This creates some coupling between the View and the Model, but that is entirely acceptable. In the MVC pattern, the View is allowed to know about the Model (and to have read-only access to it), as long as the Model doesn't know more than that "somebody" is interested in receiving change notifications.

Correct answer by Bart van Ingen Schenau on January 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP