简体   繁体   English

设计模式-解决依赖关系

[英]design pattern - solving dependencies

Lets say in C++/Qt I have class A, class B and HTTP class which is a singleton and handles GET requests. 可以说在C ++ / Qt中,我有A类,B类和HTTP类,这是一个单例并处理GET请求。

Object of class A sends GET request (thanks to instance of HTTP class) and it waits for reply. 类A的对象发送GET请求(由于HTTP类的实例),并等待答复。 When it appears, its parsed, appropriate models are populated etc. 出现时,将对其进行解析,并填充适当的模型等。

Object of class B should do the same but additionally it needs some data parsed inside object of class A. 类B的对象应该做同样的事情,但另外它还需要在类A的对象内部解析一些数据。

I know I can do that by Qt signals/slots mechanism but I'd like to use kind of design pattern cuz there are much more classes that needs to support such operation. 我知道我可以通过Qt信号/插槽机制来做到这一点,但是我想使用某种设计模式,因为有更多的类需要支持这种操作。 In my case for example one object needs to wait for data received by 3 other objects. 以我为例,一个对象需要等待其他3个对象接收到的数据。 Is there any way to solve that kindly? 有什么办法可以解决这个问题吗?

观察者模式是您正在寻找的https://en.wikipedia.org/wiki/Observer_pattern

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM