[Head First Design Patterns] Strategy Pattern
07 Apr 2022
Design pattern pros
- give you a shared volcabulary with other developers -> easily communicate with other devs and inspire who dont know start learning them.
- elevate your thinking about architecture by letting you think at
pattern level
, not a nitty gritty object level
Common design principles
Interface, Abtract class and Mixin
Interface
: including abtract methods, no concrete method and internal state
Abtract class
: including abtract methods, concrete methods and internal state
Mixins
: including abtract methods, concrete methods but no internal state
SimUDuck app
Design principles
- Identify the aspects of your application that vary and seperate them from what stays the same (encapsulate what varies)
- Program to an interface, not an implementation
- for some languages like Python which supports
multi-inheritance
, program an abstract class is acceptable
- but always keep in mind that program an interface always fexible to create your own implementation
- Favor composition over inheritance
Pattern
Strategy pattern
defines a family of algorithms, encapsulates each one and makes them interchangeable
Tags:
work
designpattern