Strategy Pattern
I finally got a chance this week to finish a screen-cast on the strategy pattern. I'd been planning on doing this way back in December but life's been rather hectic since then.
Anyhow here it is: Strategy Video
Pattern Summary
- 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.
Design Principles applied:
- Identify the aspects of your application that vary and separate them from what stays the same
- Program to a super-type (interface/abstract class), not to a concrete implementation
- Favour composition over inheritance
This video attempts to explain the strategy pattern. Apologies if it causes any confusion; this is my first attempt at presenting; criticism will be appreciated :-) If it does leave you confused please post a comment and maybe I can improve on it in the future.
'The most dangerous strategy is to jump a chasm in two leaps'
From feedback received, it was clear that applying polymorphism to specify the 'Play Music' behavior has led to some confusion. Even though the individual felt they understood polymorphism, I think they had never seen it used in conjunction with an interface. Therefore I done a quick 5 minute video discussing polymorphism.