18 July 2012

Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.

If we were to use this pattern to associate a Super Hero’s talents and powers to the hero themselves it might look like the diagram below.

Strategy Pattern
Strategy Pattern

Experience tells me I would store the powers in a persistence layer (database) and would need something more flexible. Such as a name attribute for talents and powers that would let me use one class each for talents and powers.


Less Is More ~ Older posts are available in the archive.