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
not quite sure what you mean. maybe you want the observer pattern?
Joined: Jun 02, 2010
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.
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.