有人可以简单地用信号和插槽模式来解释吗?
Can someone explain in simple terms the "signals and slots" pattern?
推荐答案信号和插槽是一种解耦的方式发送者(信号)和零个或多个接收器(时隙)。假设您是一个系统,其中有一些事件要提供给对这些事件感兴趣的系统的任何其他部分。而不是将生成事件的代码硬编码到想要了解这些事件的代码,您将使用信号和插槽模式。
Signals and slots are a way of decoupling a sender (the signal) and zero or more receivers (the slots). Let's say you a system which has events that you want to make available to any other part of the system interested in those events. Rather than hard-wiring the code that generates event to the code that wants to know about those events, you would use a signals and slots pattern.
当发送方发信号事件(通常通过调用与该事件/信号相关的功能),将自动调用该事件的所有接收器。这使您可以在程序生命周期中根据需要连接和断开接收器。
When the sender signals an event (usually by calling the function associated with that event/signal) all the receivers for that event are automatically called. This allows you to connect and disconnect receivers as necessary during the lifetime of the program.
由于这个问题被标记为C ++,所以这里是 Boost.Signals 库,其中有更详尽的解释。
Since this question was tagged C++, here is a link to the Boost.Signals library which has a much more thorough explanation.
更多推荐
什么是信号和插槽?
发布评论