WIKI:In computer programming, the strategy pattern (also known as the policy pattern) is a software design pattern, whereby an algorithm's behaviour can be selected at runtime.Formally speaking, the strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.[1]
从以上可以看出,策略模式,是对不同算法的适配,支持在运行期调用。
对于C来说,所谓策略模式,就是定义一个函数钩子,并根据不同的场景赋值,在运行期调用该钩子即可指向不同的处理流程。
举例1
1)提供消息注册机制,每个节点包括消息类型和函数钩子
2)注册消息类型及其处理函数
<