different approaches to MVC
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I thought that the View should collect some data and send it to the Model.
Is my interpretation correct? :
I think that my interpreation has less dependencies. View and Model know nothing about each other.
Scenario:
- user input some data. This data is collected by View.
- View passes that data to the Controller.
- Controller gives that data to the Model
- Model performs some calculation and send the result to the controller
- Controller sends the result to the View.
So in my interpretation - controller notify the View about updating.
Let's discuss. What do you think.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
- user input some data. This data is collected by View.
Yes, this is how is works.
- View passes that data to the Controller.
In addition to passing the data, there is also some "action" or "behavior" which is invoked within the Controller. A user clicks on a Submit button, for example.
- Controller gives that data to the Model
Yes, this is how it works. Controller may create Transfer Objects with the data or reformat the data depending upon how it is received.
In addition to passing the data, there is also some "action" or "behavior" which is invoked within the Model application.
- Model performs some calculation and send the result to the controller
Yes, this is how it works. Keep in mind that the Model application shouldn't be invoking methods on the Controller. So, there is no need for a Controller reference in your Model.
- Controller sends the result to the View.
Yes, this is how it works.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
James Clarks wrote:
- View passes that data to the Controller.
In addition to passing the data, there is also some "action" or "behavior" which is invoked within the Controller. A user clicks on a Submit button, for example.
OK, let's say that a user clicks a Submit button. Can I invoke that action after clicking (in MVC concept)? :
James Clarks wrote:
- Model performs some calculation and send the result to the controller
Yes, this is how it works. Keep in mind that the Model application shouldn't be invoking methods on the Controller. So, there is no need for a Controller reference in your Model.
OK, so keeping the reference to the View (instead of Controller) in the Model is a good option? After performing some calculations, model will notify the View to update.
Am I right?
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
OK, let's say that a user clicks a Submit button. Can I invoke that action after clicking (in MVC concept)? :
First, the Model-View-Controller design pattern is a "pattern". A "pattern" does not concern itself with specific implementation details such as "a user clicks a Submit button."
In regards to our theoretical, simplified implementation, if a user invokes the Controller action by "clicking on a button", there is no way for a user to invoke the action after he already has, except by "clicking on the button" again if the UI is designed this way.
OK, so keeping the reference to the View (instead of Controller) in the Model is a good option? After performing some calculations, model will notify the View to update.
No, the Model application should not have ANY dependencies on the Controller or the View. Behavior in the Model is invoked by a Controller and responds to the invocation be sending data back or some kind of response code indicating that it has executed the behavior.
A Controller has a reference to something in the Model. A Controller has a reference to something in the View.
The Model application does not have any reference to a Controller or a View.
All of the intelligence involving View and Model interactions is coded in a Controller. Controller has intimate knowledge of View and how to invoke operations on Model.
The ultimate goal of MVC pattern is the ability to easily change or add new Views to the Model, WITHOUT having to make any changes to business logic in the Model. NO CHANGES IN MODEL. NOTHING...

-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please, consider this improved concept.
Scenario:
- user fills the form up and clicks the button,
- void buttonClicked(...){ //this method is from the view
//create data object from the form
controller.compute(dataObject);
}
- controller request the model to compute and get computed data:
computedData = model.getComputedData(dataObject); //this method is from the controller
- controller notify the view:
view.update(computedData);
Is it good approach? And is that in term with MVC?
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Controller:
public ActionForward executeAction(Action act, Object data);
Model:
public final Object compute(Object obj);
I suggest that you learn the Struts Framework. It is a very good example of a Controller and a View and will help you build a MVC-based application.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
So my approach is totally bad?
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Can I use enum as Action?
You could certainly try. If it doesn't work out then try something else.
In regards to your approach, if you can execute business logic (Model) from a command-line, i.e. standalone application, and if you can execute the same business logic from a HTML web page, then you have implemented MVC properly.
Repeated for emphasis...
The ultimate goal of MVC pattern is the ability to easily change or add new Views to the Model, WITHOUT having to make any changes to business logic in the Model. NO CHANGES IN MODEL. NOTHING...

-
-
Number of slices to send:Optional 'thank-you' note:
-
-
James Clarks wrote:
OK, let's say that a user clicks a Submit button. Can I invoke that action after clicking (in MVC concept)? :
The Model application does not have any reference to a Controller or a View.
That needn't always be true. For instance, for a rich client application implemented using Swing or some such framework, it might make sense to use the Observer/Observable paradigm. Using the default implementation in java.util you could have the model class(es) (extend Observable), have the view and controller classes implement the Observer interface and have both views and controllers register themselves to the model. That way that model does have a reference to the controller, except that it doesn't know it's a controller, but rather just some registered observer wanting to be notified of state changes.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-

SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
| Maybe he went home and went to bed. And took this tiny ad with him: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








