开发者

Design Pattern Between Two Object's Interaction

开发者 https://www.devze.com 2023-03-23 00:56 出处:网络
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

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.

Design Pattern Between Two Object's Interaction

0

精彩评论

暂无评论...
验证码 换一张
取 消