• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Example of delegating responsibility ?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an instance target being a member in an instance (owned by) o of class O. An instance u of class .U. should be able to express desire to make o change the state of target but not directly, so through an instance ui of class UI. Can someone give me an example of some Java class having code doing this in a nice way or maybe name the pattern I am close to here ? Might be time to get a book on design patterns
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not quite sure what you mean. maybe you want the observer pattern?
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets say we have a MediaCenter class. You can hook up all your elctronic gadgets to a MediaCenter. Now maybe there is an interface MediaController which provides the methods necessary for controlling instances of DvdPlayer, Projector instances etc. through the MediaCenter. Now you could have different classes MyPhone, Remote and similarly implementing MediaController to make them able to message the MediaCenter about increasing the volume on speakers, turn off the TV etc.
So the point where I dont feel I have a nice solution is how to "get a message" through from eg. a Remote to the MediaCenter endning in eg. the speakers.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're having trouble passing information between your "gadgets" I would suggest applying a new interface that will ease all of that communication. The Facade pattern is a pretty good one. If you just want your classes to be able to notify each other without going through a medium, I would use the Observer pattern like Mark suggested.

Facade
Observer

Hunter
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic