Reputation: 1431
MVC pattern separates data model, GUI view and event handling by controller. One can make Model the entry point
public class MyModel {
private Integer value;
MyView view = new MyView(this);
MyController controller= new MyController (this);
//MyController controller= new MyController (this, view);
}
Or, one can start with Controller and create model and view from controller.
Which class should be be called first and create other two classes?
Upvotes: 1
Views: 445
Reputation: 10003
I usually make a main class that is an observable and have the main class create the model, views, and controllers and then add the views to the model.
Upvotes: 0
Reputation: 3433
None of the above. You "generate" each part of the architecture from your source-code editor.
The view collects (user) input and performs surface edits (superficial validation) on them. Assuming valid input (e.g., no non-digits in what should parse as a number), the controller selects (not generates) a model component to which to pass the parsed or validated inputs, pushes the resulting data to the selected model component, then forwards the model identifier to a view renderer.
The model performs business logic on the inputs it receives from the controller, then packages any results in an expected format, such as a result type.
The view that received the forward from the controller makes a pull request from the model for the result object, then displays it to the output channel of the app.
It is possible that some piece or other of that all might be generated dynamically, but that is not an essential aspect of the architecture. The controller might invoke a model factory, for example, then push data to the received model instance. Here, it's not the controller generating the model class, but selecting one with the assistance of the factory.
Summary: View receives input, massages it, and submits it to the controller. Controller selects, not generates, a model and a new view. Controller pushes inputs to the model and forwards the model identifier to the new view. The new view pulls the result from the model and displays it to the output.
Read http://download.oracle.com/otn_hosted_doc/jdeveloper/1012/developing_mvc_applications/adf_aboutmvc2.html for a fundamental introduction to the concept. (This page took me less than five minutes to find with an online search.)
Upvotes: 1