`

One Note of Head first design patterns (Strategy pattern)

阅读更多

Today ,I read the chapter one of the Head first design pattern,and i found the book  was a  exicting book.

now i just want to sum it up.

         The chapter one tell us a pattern called Strategy pattern,Frist of all ,we should   know  the  formal  

definition  of  the  pattern, Here is  it .the Strategy pattern defines  a   family  of  algorithms , encapsulate

each one , and makes them  interchangeable.do as this  , a   algorithm will    vary independently from the

clients that use it .

        The point of this pattern is finding  out the changable parts from the system,and encapsulating them

into a independent unit .In the concrete project,what we need to do is finding chang-  es and encapsulating 

them into a class or a interface.and the  client only  know the abstract   class or interface ,and don't  need

take care of the implementments.

        This pattern relate to three roles, one is the context part ,another is the abstract  strategy  part  ,and

the rest  one is the concrete strategy part .what we need to do just is implement the concrete

strategy ,what'more ,the context don't need to know the concrete implements.Here is the  class Diagram

                             .

       

         This chapte also tell us some oo design principles.As are show here.

          1 . identify the aspects of your app that vary and separate them from what stays the same.

          2 . Program to interface ,not to implementation.

          3  . Favor compositon over inheritance .

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics