Question

I have two objects, ObjectA and ObjectB. ObjectA needs to call events on ObjectB. I was looking for a good design pattern to allow ObjectA to do this, because I don't want to expose public methods for anyone to do this, yet ObjectA really needs to do the work of firing those events.

Is there a good pattern for this, or any advice?

Thanks.

Was it helpful?

Solution

ObjectA needs to call events on ObjectB

well the way you describe it sounds like A sending commands to B, which makes Command pattern a usual suspect.

Also the way to establish close encounters between A and B may turn out complicated enough to justify establishing a separate object C to mediate their interaction - Mediator pattern

OTHER TIPS

If an object needs to call methods from another class, it doesn't really sound like good design to begin with.

Perhaps consider the Observer Pattern. This is usually used when one object needs to receive notification from another object.

UML From Wikipedia

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top