/** * This program represents a basic MVC architecture. * * The model maintains a single string that is input by the user using the GUI and echoed on the * GUI. * * The view is the GUI. * * The controller reacts whenever the user presses a button. It acts as a communicator between model * and view, and thus separates them. * * Advantages of this design: * * 1. Changing the GUI but not the functionality (model) is possible and clean. 2. Using a new * implementation of the model without changing view and controller is possible. * * Limitations of this design: * * 1. The controller is somewhat tightly coupled with the GUI, because it implements some * Swing-specific interfaces. For larger programs, this coupling may be costly when the GUI must be * re-created using a framework other than Swing. * * For such cases, it may be worthwhile to define generic interfaces for possible listeners in the * GUI (i.e. button press, menu selection, keyboard/mouse events, etc.) and then write adapters to * make the controller work with specific GUIs * * 2. Handling keyboard and mouse events is not covered yet. This must be done in a scalable manner, * because the key mappings (which keys do what) should be easily changeable, and should be * changeable by the controller and not mandate a rewrite of the view. */ public class MVCExampleBasicMVC { public static void main(String[] args) { IModel model = new Model(); Controller controller = new Controller(model); IView view = new JFrameView("Echo a string", controller); controller.setView(view); } }