-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMVC design ideas.txt
10 lines (10 loc) · 2.55 KB
/
MVC design ideas.txt
1
2
3
4
5
6
7
8
9
10
As this is my first time to design a MVC program and decide to do it from scratch, I will write down all the thoughts about how to make it happen here.
05.25.2017
The professor from Digital Image Processing said once think big start small. The view of this program shall change with the need, however, it's quite easy to decide what I want it to look like at first place. So, let's start with view.
06.13.2017
I have finished 1.0 version. A lot to cover in the future, if this gets any other users. I didn't write down the progress when doing development. I was always coding and debugging. Although, some details may be forgetten, here is the makeup for the brainstrom I did:
1.
View contains two parts: a window(JFrame) + different panels(JPanel). Windows should have menu and always be the same size.Panles should be designed by different needs of this program. These panels can be added to the Window at very beginning. Since the contentPane in JFrame allows multiple layers of panles. However, if these are all visible than the only thing you can see is a piece of mass. Thus, after adding panels to the window, make sure only one panel should be visible at a time. And all the functional view components, like button and label, should be accessible by controller.
2.
Controller must listen to the action event of view. So, it must implements java.awt.event.ActionListener. And it should register itself to the observable view components, so that any user action will be caught by the controller. By this, we have a communication channel from view to controller. What about from controller to view? It's simple, as controller knows anything about its pair view which makes every functional component public to controller, when a controller want to change something in view, it just needs to do this: view.textField.setText("I am changed!").
Next, we may use similar methods to build channel between controller and model. We implement observe pattern to model, controller is observable and model is the observer. Once an action happens, public void actionPerformed(ActionEvent e) of controller should be called, and inside it, we call all models of this controller to respond with this action. To do this, we make every model class implement a helper class MessageHandler, besides, each controller has a list of MessageHandler, and they are sent with a message by controller's sendActionMessageToHandlers(source,command) inside public void actionPerformed(ActionEvent e). How about message from model to controller? Each model has a controller field, and that's it, it can directly speak with its controller.