The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.This pattern is a means of exchanging members of a family of algorithms without impeding the operation of clients. It requires programming to an interface, not an implementation. The pattern grants clients consistency because concrete algorithms in use are members of the same family or interface.
Head First Design Patterns implements Strategy Pattern in an interesting way. Rather than provide a class with behavioural methods, they have the class delegate behaviour to an interface. Concrete behaviours have to implement their particular interface. As a result, ducks behave appropriately!
No comments:
Post a Comment