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.