I've learned MVC (model-view-controller) but I've been unable to figure out how to implement it in a way that respects encapsulation between the three components.
For example, I was always taught that the front end and back end should be completely separate, and should never interact. But in MVC, the Model actually mutates the view, which means the model has a reference to the view.
Similarly, the controller needs to take in input from the front end (ex. button, text box, etc) and mutate the model. How can the controller be both separate from the view AND have its components (button, text box) inside of the view (otherwise they wouldn't be shown to the user). Wouldn't this mean the view would have to be mutable?
I asked my professor about this, and pointed out some violations in abstraction and encapsulation with MVC and he responded by saying that "it is part of the design, to responsibly use references to the view and model. If someone designing the model happens to take advantage of the lack of encapsulation of the view, then it violates the contract of the design."
Is there a way to implement MVC in a way where no one component can cause harm to another (ex. model cannot delete the scene of view, controller cannot null-out all data inside of model, etc etc). Is the key just to setup many accessors/mutators in view & model?
Aucun commentaire:
Enregistrer un commentaire