I am looking into the MVC from a Command line point of view (not web and no framework).. nice and simple. the only thing that confuses me is the View part of this? (well it may not be the only but its the main one)
from the IBM site the view has the following definition
The view provides the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.
So if i have the following:
Model
- Person
View
- EditPersonDetails
Controller
- PersonController
My person controller could pass a person object to the EditPeronDetails view, however how does my view edit the person if it cannot access its setters, how can i edit the person?
Also does the view class only do one thing? ie can I have a Person View, which has methods for Create, View, Delete, edit the person
many thanks
bones
I'm working on re-architecting a trivial CLI program and have asked a similar question to myself.
In researching this, it's apparent that MVC and its derivatives are commonly misused. To complicate things further, variations of MVC (Web MVC comes to mind) exist that don’t adhere to the almost-original Smalltalk-80 implementation and definition of MVC.
That said, I like dfa's answer with one caveat: the user input should be placed in the controller, not the view. His answer aligns more closely with the Dolphin Smalltalk MVP pattern than MVC.
As such, I would remove:
from the view and simply have the controller wait for input as follows:
To be honest, I have a hard time justifying this as necessarily better, but thought I would throw out there.
define an abstract yet simple MVC program as:
then use the Observer pattern (built-in since JDK 1.0, see here) in order to fill the concrete classes:
The main class, that is only responsible to build and connect together the components:
the ouput of this program is:
I'm not sure to get how you transposed the concept of view on the command line but I'll try to answer.
It doesn't, the controller does. The view only "captures" new values and actions and send them to the controller which handles them and updates the model.
A view can do multiple things. For example, a same form could be used to create, read and update a domain object (by create and edit, I mean capturing values and sending them to the controller). This is actually a very common pattern. But as I said, it's not the view that performs the logic, it's the controller that does.
So, to answer your question, I guess we can imagine having dedicated methods on the Person View to capture the user input and to handle communication with the controller, but not for the CRUD logic (I'm really wondering how you handle interactions with the user on the command line, it doesn't seem really handy for a CRUD application).
Is it really necessary to apply a 3 letter acronym here? if you must:
psuedocode: