美文网首页收集一些技术好文
Strategy pattern is good for som

Strategy pattern is good for som

作者: JoeJiang | 来源:发表于2017-09-15 22:06 被阅读83次

    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 (江东敏)

    相关文章

      网友评论

        本文标题:Strategy pattern is good for som

        本文链接:https://www.haomeiwen.com/subject/jdhssxtx.html