MVC ARCHITECTURE:
MVC ARCHITECTURE:
Model view controller, (MVC), is a user interface design decomposition that breaks down components into three parts: a model, a view and a controller.
In this three-way separation model, a mode l is responsible for maintaining all aspects of the component state e.g whether a button was pressed or unpressed, the character data of a text component, the opacity value of a window. A model communicates indirectly with the view and the controller i.e this communication is carried out without the model knowing its view or controller.
The view is the visual representation of the component's model or what is called the “look”. One noticeable example is the font of a character on a button or color of a label. The view receives indirect messages from the model and direct messages from the controller and is responsible for keeping its on-screen representation updated.
The controller is responsible for event management or the reaction of the component to events such as input devices such as the keyboard or mouse. The controller is the “feel” of the component, determining component actions. The controller receives direct messages from the view, and indirect messages from the model.
Let's illustrate the MVC concept: imagine a button with the state unpressed. On the model, this is the state and the view shows a button that is unpressed, idle. If a user clicks on the button, an event received by the controller, the controller translates this as a press or the button sends a direct message to the view, the view now looks “pressed” and send a message to the model to change its state to press = true.
Advantages of the MVC architecture:
1.we can customize the “look”(view) and “feel”(controller) of a component without affect the model.
2.We can customize specific parts of a component without affecting the model.
3.We can customize and replace a component's data model.
If you check the api there are various interfaces for the swing components that implement models and you will find references to the models that are implemented. In the course of the following weeks we will also be implementing this models in our classes for the swing components.
No comments:
Post a Comment