MFC中2个无关类之间的交互 [英] Interaction between 2 unrelated classes in MFC

查看:98
本文介绍了MFC中2个无关类之间的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有个问题.在我的项目中,我有2层,即UI层和Network层. UI层保存N/W层对象.但是N/W却没有.这是因为我不希望这两层紧密结合.现在,我想在接收任何数据时从N/W向UI发送消息.我不应该将HWnd作为N/W中的数据成员,因为它会导致紧密耦合.

因此,请提出如何从网络层向UI层发送消息/通知的建议?

问候,
Deepika

Hi All,
I have a question. In my project, I have 2 layers i.e. UI layer and Network layer. UI layer holds the N/W layer object. But the N/W doesn''t. This is because I dont want both layers to be tightly coupled. Now, I want to send message to UI from N/W on receving any data. I should not have HWnd as a data member in N/W as it will cause tightle coupled again.

So, please suggest how I can send message / notification from network layer to UI layer?

Regards,
Deepika

推荐答案

您可以为此使用委托.这样,您只需为n/w层提供一个指向UI层中的函数的指针. UI层中的功能与已在n/w层级别定义的预定义签名匹配.这样的预定义函数签名的名称称为委托.
http://www.functionx.com/cppcli/classes/Lesson15c.htm [ ^ ]

祝你好运!
You can use delegates for that. With that you simply give your n/w layer a pointer to a function in the UI Layer. The function in the UI layer matches the predefined signature that has been defined at the n/w layer level. The name of such predefined function signature is called a delegate.
http://www.functionx.com/cppcli/classes/Lesson15c.htm[^]

Good luck!


查看适配器模式: http://en.wikipedia.org/Wiki/Adapter_pattern [ ^ ].
Check out the adapter pattern: http://en.wikipedia.org/wiki/Adapter_pattern[^].


这篇关于MFC中2个无关类之间的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆