Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Observer pattern

 
Timmy Ryan
Ranch Hand
Posts: 63
IntelliJ IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a checkers game.

Model contains the game state and the view naturally displays the game.
The view is contained in a JFrame 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(JPanel instence) for the view to be notified when the model is updated.
Should I make the JPanel instance a singleton?

Kind of confused with so many references floating around.
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic