Lesson
Strategy Pattern Overview
Strategy Pattern Overview
The Strategy Pattern enables you to define a family of algorithms, encapsulate each one as an independent collaborator, and make them interchangeable at runtime.
By separating the invariant workflow orchestration from volatile algorithmic or policy choices, your domain logic remains closed for modification yet open for extension.
Architecture & Structure
graph TD
Client[Client / Context] -->|delegates to| Strategy["<<interface>> Strategy"]
Strategy --> ConcreteA[ConcreteStrategyA]
Strategy --> ConcreteB[ConcreteStrategyB]
Strategy --> ConcreteC[ConcreteStrategyC]
Computational Complexity & Invariants
Using dedicated policy collaborators guarantees stable runtime characteristics:
In this module, you will:
- Identify stable roles: isolate orchestration interfaces from concrete channel implementations.
- Handle changing policies: model variable pricing and discount strategies as interchangeable policy collaborators.
- Connect policies to checkout: inject policy collaborators into cart and checkout workflows.
- Integrate the complete workflow: coordinate policy, state, and presentation into an end-to-end service.
Sign in with Google to save your lesson progress.
Sign in to track progress