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:

Strategy pattern is good for some situation in some system._第1张图片
image.png

3. Clase Structure:

Strategy pattern is good for some situation in some system._第2张图片
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 (江东敏)

你可能感兴趣的:(Strategy pattern is good for some situation in some system.)