File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looking for Java pattern

 
Ahmed Basheer
Ranch Hand
Posts: 77
  • 0
  • 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
  • 0
  • 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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic