Strategy pattern is good for some situation in some system.

Copyright @ Joel Jiang(江东敏) at 2017.09.15 22:00 p.m
in Shenzhen.China. LIST- TE- E33 -01

1. Introduction:
When the system demand is vary frequently, so that the design arithmetic will be change follow it. Maybe someone will use the "code cover" ,I don't this word is fit for explain it accurately. Chinese meaning is "代码复用".(About "code cover" is not easy word is here ,is not equal to copy some code to the other room in some extent.Here we dont detailly illustrate more.) there is many coding will program as follow:

image.png

If you are a sophisticated programmer, you may find many quetion in here in code frame ,if the demand change frequently,and per demand have not a relative each other per se. if will often copy lots of "if..." code case to other place . But it is difficult. Because very state have not relate in all the demand.And you must program code somewhere,that you change all the system code. Here we talk about the strategy pattern ,a out way to let you settle the question. Strategy pattern is use basic class and derived class , such as:

2.Code templet:

image.png

3. Clase Structure:

image.png

4.Strategy and open/closed principle
Since accelerate and brake behaviors change frequently between models, a common approach is to implement these behaviors in subclasses. So we must design the code basic on the open/ closed principle .yet not just open or close the class. The strategy pattern uses composition instead of inheritance, In the strategy pattern, behaviors are defined as separate interfaces and specific classes that implement these interfaces. This allows better decoupling between the behavior and the class that uses the behavior. The behavior can be changed without breaking the classes that use it. Behaviors can also be changed at run-time as well as at design-time.

The sharing of knowledge, the spirit of encouragement.
By Joel Jiang (江东敏)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,450评论 0 23
  • 刚刚加入销售部的玲最近陷入了一个烦恼! 工作需要,每天非常勤快的在朋友圈刷屏产品,乐此不疲,只是可怜的点赞数廖廖无...
    陈少琼阅读 2,662评论 8 13
  • 年少时希冀, 踏遍天涯路, 何处无青山处。 月圆时他乡, 高台客望尽, 不见云海归处。 年华啊年华, 纵是乡情应不...
    文澜海阁阅读 1,638评论 0 1
  • 公司派我去培训 真心不想去 因为一旦辞职还得赔钱。 哈哈哈 不过想想去看看也不是什么坏事 哎~还是不想去~还是想辞职
    面包和牛奶都会有的阅读 767评论 0 0
  • markdown是一种轻量的标记语言。刚接触markdown,熟悉了简单的命令,记录下来。 关于标题 如果你编辑:...
    鱼f阅读 2,707评论 0 2