Design Pattern Between Two Object's Interaction
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,开发者_如何学Python or any advice?
Thanks.
If an object needs to call methods from another class, it doesn't really sound like good design to begin with.
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
Perhaps consider the Observer Pattern. This is usually used when one object needs to receive notification from another object.
精彩评论