File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes design pattern and mvc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "design pattern and mvc" Watch "design pattern and mvc" New topic

design pattern and mvc

Thankmar Kronzucker

Joined: Nov 09, 2001
Posts: 1
my question concerns Design Pattern, particulary observer pattern in Java.
I want to programme a board game called TWiXT. The subject of this game is not important, but the way how to implement is pretty decisive. GUI and application layer must be separated from each other. Data concerning the flow of the game must be hold in the application layer. Every view or presentation of data and also interaction takes place in the GUI.
In order to keep the GUI dumb the observer pattern could be applied. So far so good. For this I implement an interface that separates the GUI from the application layer. The GUI is allowed to communicate by this interface only.
What happens when a user does an interaction. The GUI uses the interface to send a message to the application layer. The application layer determines wheather this message changes the state of data. If it does, so the required change will be done. Hence it follows that the application layer must let the GUI know that data changed in order to make the GUI update the presentation of data.
Yeah, that's pretty lot so far, but the more precise the question is, the more precise is hopeful the answer. And here is the crucial question:
How can I let the GUI know what kind of change happened? If I define several states so that the GUI can query them in order to decide what to do, the GUI will have a portion of intelligence and thus know what's going on in the application layer. This is the crucial point: The GUI mustn't know so much about the application layer.
Do you have any bright idea? Are there "prefabricated" pattern solving this problem?
Any hint is higly appreciated.
THX in advance.
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Well, with an Observer pattern you're on the right track. In an MVC model, it's usually the View that observes Model state. That way, multiple views on the same model are possibly by simply registering themselves as observers. I'm less convinced about using the pattern between Controller and Model though.
For more inspiration, have a look at the way a javax.swing.JTable detects changes in its underlying javax.swing.table.TableModel by implementing the TableModelListener interface and registering itself to receive TableModelEvents.
- Peter
I agree. Here's the link:
subject: design pattern and mvc
It's not a secret anymore!