Is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures. It is one way to easily follow the OCP (Open Closed Principle)
- Makes adding new operations easy
- Gathers related operations and separates unrelated ones
When to use:
- An object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes.
- Classes defining the object structure rarely change, but you often want to define new operations over the structure