• Post Reply Bookmark Topic Watch Topic
  • New Topic

Observable patter in GUI

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I'm using the observable pattern for my GUI. I have created a own Interface for registrating Subjects and Publishers to communitate.

Problem is that in many times I have 15 classes both as a publisher and a Subscriber to oneanother.

This means that a ShapeManager can both be subscriber and publisher to a ColorPicker class.
This work in the beginning but know I'm have a cillion classes in at nest talking to each other. It's beginning to be unbareable to continue with this. How do you do this communication between guis?

Do you have a better ide then to do it like this?
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use the mediator design pattern to coordinate all the Observers and Observables. In this way, they don't need to talk with each other, the publishers publish the message to the mediator. The subscribers subscribe the message they are interested.

Read GoF book for concepts and examples...

Thanks!
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do you have a better ide then to do it like this?

What does your IDE have to do with fundamental design questions?
My big question is why are your ShapeManager (presumably a palate of shapes) talking to your ColorPicker (presumably a palate of colors)? Wouldn't you have some sort of work area (lets say a document) which would display the various shapes of various colors, and it would be the common listener for all the palates? Or wouldn't it be the individual widgets in the document itself that are created/effected by the various pallets?
In any case, when managing observable becomes overwhelming, it is time to consider taking that functionality out of your classes and using an event bus of some sort to manage messages between components.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your responses. I know that the code has grown beond control and that the design is bad. I will consider your alternatives and do some reading.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!