Design patterns implementation examples

Strategy

Definition:

Defines family of algorithms encapsulate them in classes facilitates their exchange.


Example:

Packing program services different algorithms of data compression. The program is written in such way that adding new algorithm does not make a significant change in its servicing, one only has to choose different compression type form the list, the procedure of packing does not change.


C++ code:

/src/strategy.cpp
Download source code

Strategy UML class diagram:
Strategy UML class diagram

Strategy UML sequence diagram:
Strategy UML sequence diagram