File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java SE 8 for the Really Impatient
this week in the
OO, Patterns, UML and Refactoring
Joined: Dec 09, 2007
Aug 23, 2011 14:14:41
I have a checkers game.
Model contains the game state and the view naturally displays the game.
The view is contained in a
and this contains a few JPanels.
The model extends Observable and one of the views JPanels implements Observer.
When creating the model instance to hold the game state I need to run addObserver(
instence) for the view to be notified when the model is updated.
Should I make the
instance a singleton?
Kind of confused with so many references floating around.
Joined: Oct 14, 2005
Aug 23, 2011 14:34:32
If you need only one of those Observer panels in your application, then just create one of them. There's usually no need to go through all that tedious Singleton business when a simple "Observer whatever = new ObserverPanel()" will do.
I agree. Here's the link:
subject: Observer pattern
Separating View-Controller in MVC
Adding an action listener to an entire class
MVC and Observer Pattern
problem in refreshing JPanels in cardlayout
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014