Design Patterns 4 : Strategy

来源:互联网 发布:maomiav域名紧急升级 编辑:程序博客网 时间:2024/06/03 16:31

      You got something to do and based on the contexts you need to do it in different ways.

 

      You could mix the contexts with the things together, like a switch cases.

      Or you could define a interface and implement the interface according to different conditions, and choose which implementation to use based on the context. 

 

      Strategy is way to push down the variation in the hierarchy, instead of changing yourself (through inheritance), make someone else polymorphic and contain it.