Pushing all the events through a single routine is a violation of object encapsulation. It also increases coupling. That one routine has now knowledge about the interactions among many other objects. Because of the same, we are also violating DRY principle, as well as orthogonality.
Objects should be able to register to receive only the events they need, and should never be sent events they don't need.
Model View Controller
Suppose we have a spreadsheet application with some data. In addition to the sheet, we need to show the data as a graph/pie chart, and also a table with total data. But here we don’t want separate copies of data for each representation.
How do we tackle this problem?
We can create a model with the available data and common operations to manipulate it. Then we can create separate views, which use this model to display the data in various formats such as sheets, pie/bar charts or tables. Each view also has a controller which takes care of manipulating the model data into the particular format.
Our basic objective is this:
Separate Views from Models
As the coupling between model and view reduces, the flexibility and reversibility of the code increases to a very large extend.
- summary of It’s Just A View, from The Pragmatic Programmer: from Journeyman to Master
Objects should be able to register to receive only the events they need, and should never be sent events they don't need.
Model View Controller
Suppose we have a spreadsheet application with some data. In addition to the sheet, we need to show the data as a graph/pie chart, and also a table with total data. But here we don’t want separate copies of data for each representation.
How do we tackle this problem?
We can create a model with the available data and common operations to manipulate it. Then we can create separate views, which use this model to display the data in various formats such as sheets, pie/bar charts or tables. Each view also has a controller which takes care of manipulating the model data into the particular format.
Our basic objective is this:
Separate Views from Models
As the coupling between model and view reduces, the flexibility and reversibility of the code increases to a very large extend.
- summary of It’s Just A View, from The Pragmatic Programmer: from Journeyman to Master
No comments:
Post a Comment