Advantages of using strategy pattern in php

前端 未结 6 806
耶瑟儿~
耶瑟儿~ 2021-02-02 13:42

I can\'t seem to get my head around what advantages the strategy pattern offer. See the example below.

//Implementation without the strategy pattern
class Regist         


        
6条回答
  •  伪装坚强ぢ
    2021-02-02 14:37

    A couple of important features of the Strategy pattern as envisioned by the Gang of Four are:

    1. It has no conditional statements (so leave out your switch, if, etc conditionals)
    2. It has a Context participant

    Most of the advice on the Strategy leaves out the Context participant. You can find five different examples of the Strategy pattern in PHP here: http://www.php5dp.com/category/design-patterns/strategy/

提交回复
热议问题