Sunday 25 June 2017

Software Engineering: Strategy Pattern

Behavioural Pattern - Strategy Pattern


Intent
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Similar to Template Method, but instead of changing the entire class, this enables an algorithm's behaviour to be selected at run time as an object.

How is this applied?
  • For variants of an algorithm. 
  • For example you might define an algorithms reflecting different space/time-trade offs.

UML diagram representation
Strategy example

https://sourcemaking.com/files/v2/content/patterns/Strategy_example1-2x.png

More to follow...

No comments:

Post a Comment

Software Engineering: Bad Smells! (Smelly code)

Bad Smells! What are bad smells? This refers to any symptom in the source code of a program that possibly indicates a deeper problem.  ...