Desing patterns

Strategy pattern
Encapsulate the problem that varies (algorithm) and program to an interface, not an implementation

– related classes differ only in behavior (not data) – configure them with one of many behaviors
– many algorithms to solve problems
– algorithm uses data (internal structures) that client shouldn’t know
– a class defines my behaviors – multiple condition statements in method(s)

– All algorithms implement the same interface (with execute() method).
– The context class takes a reference to that algorithm interface via setter parameter – the reference of the particular algorithm obj is passed to the context.
– The context calls its execute() method that internally calls the execute method on the specific algorithm implementation (delegate) via polimorphism.

E.g. a component for file converter (doc to text/test to pdf … converter)

Building loosely coupled collection of interchangeable parts. This makes the software more extensible, maintainable and reusable.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s