This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "design pattern and mvc" Watch "design pattern and mvc" New topic
Author

design pattern and mvc

Thankmar Kronzucker
Greenhorn

Joined: Nov 09, 2001
Posts: 1
Hello,
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
author
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: http://aspose.com/file-tools
 
subject: design pattern and mvc
 
Similar Threads
PreAssessment Questions and Answers
Answers to IBM 486 sample test
Mark's MVC design - all controller methods private?
Passed SCJD with 137/155
Design issues with local-remote Data class