2) FBNController--> access data from the DataClient to implement business methods such as searchFlight(), bookFlight(), setComboBox(), setTableHeader(), setTableData(),etc. These methods updates (and returns) either the FBMTableModel or FBNComboBoxModel.
Originally posted by Eugene Kononov:
[QB]
Oh, my favorite subject.![]()
The implementation of business methods such as searchFlight() and bookFlight() belongs to the Model, -- that's exactly what Model is for, -- to model the business.
The methods setComboBox() and setTableHeader() belong to the View where the combobox and JTable are displayed, -- this is exactly what the View is for, -- to render the data. Neither Model nor Controller should call these methods, and neither Model nor Controller should even know how the data is rendered. For the same reason, neither Model nor Controller should return something like FBMTableModel or FBNComboBoxModel.
If you understand the following, you would be able to design your MVC so that each part in MVC has a well defined set of responsibilities:
Model -- encapsulates business logic and holds the application "state". When the application state changes, the model notifies the registered views about the change.
View -- renders the data. May receive the notifications from the Model and update itself. May use the state query methods of the model to update itself. Acts as a Model listener.
Controller -- listens for user actions and maps these actians into businees methods (i.e. invokes the business methods in the Model)
Can you please explain with a simple example??
Notice how Model, View, and Controller are each responsible for a narrow, well defined set of responsibilities. Ultimately, this translates into a high level of reuse. For example, you can replace JTable in the GUI with some other widget, and not a single line of code needs to change in Model or Controller. Similarly, you can change the business logic in the model, and again, nothing needs to change in the Controller or the View.
Eugene.
Can u provide a detailed explaination. I could not understand the following code in the example:
// The callback method, -- Mark's idea
public void searchFlightsAction(ActionListener action) {
searchFlightsButton.addActionListener(action);
}
Everything working fine, except that the JComboBox values are not populating when the Window is opened. I have added a WindowListener to the main window (View)and put the getFieldValues() method in the WindowOpened()of the controller class. But nothing is coming up while opening the window. Any idea what might be the reason??
Originally posted by Eugene Kononov:
I would suggest that you don't use WindowListener as the trigger for populating the origin/destination comboboxes. Rather, it should be either a) connect to database action (if you are implementing the dynamic on the fly switching of the database, or b) the call to a corresponding method in the model, when your model is instantiated.
Eugene.
[ March 13, 2003: Message edited by: Eugene Kononov ]
Given your comment at the top of the code sample that this is in fact an Observer-Observable pattern, would it be advantagous to this philosophy to use the Observer interface and Observable class thus making the MainFrame a subclass of Observable, and the FlightsController implement the Observable interface.
But in our case, who is the action event generator?
Can I implement the menu bar in the DataView class?
Dont you think that the design you sugested is "too much" for the the SCJD assingment? The assignment states that "A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one"
Do you I think that, for such a small application as de SCJD, the controller "role" should be coded in a separate class?
The three roles: M,V and C; must be implemented separatedly (separation of roles is the key point in MVC), but not necessarily separated by a class. For the FBN, I think that the controller role could be played by listeners coded as inner classes in the main frame without breaking the MVC rules. These listeners would be "reacting to the user gestures", sending messages to the model and updating the view with the results.
What would act as a controller for that additional View, -- another set of inner class in that view?
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|