This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looking for Java pattern

 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have complex issues of relating objects. LifeCycle which I don't have a control over starts my objects. Lets say I have class A, Class B and Class M. I need to make a relationship so that objA and ObjB knows about objM. General design of objects A , B and M is as follows

class
{
start()
stop()
}
and LifeCycle does e.g new A().start(). LifeCycle, and not me, know about these objects but I want to have some mechanism in place so that ObjA routes the calls to ObjM and ObjB also routes calls to objM. ObjB and ObjA don't need to know each other. I can't have ObjM singleton at all, otherwise solution would be simple.

Any suggestions are encouraged.
-Basheer
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a little clip from my Messaging Patterns page that might apply ...

This is a variation on observable where subscribers sign up with an intermediary to receive messages. The intermediary manages all subscribe and unsubscribe operations, and perhaps maps message types to subscribers. Message originators pass new messages to the intermediary, which then passes them to subscribers. This has some interesting features.

Subscriber and publisher life spans are decoupled. A subscriber could exist "permanently" for the life of the application, while publishers are created and destroyed. A subscriber might not be available in real-time. The intermediary could hold messages until the subscriber picks them up later. There can be multiple sources for identical messages.

I implemented an abstract intermediary that does the subscribe & unsubscribe parts. Concrete intermediaries implement the publish methods. Here's one:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic