The Strategy pattern is a behavioral GoF design pattern by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides that defines a family of algorithms, encapsulates each one and makes them interchangeable. The algorithm can then vary independently from the clients that use it. The pattern suits related classes that differ only in behavior, several variants of one algorithm, and algorithms whose data clients should not know about.
GoF-Strategy Pattern
Details
- Full Name
-
GoF Strategy Pattern (Behavioral)
Intent:
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
When to Use:
-
Multiple related classes differ only in behavior
-
You need different variants of an algorithm
-
An algorithm uses data that clients shouldn’t know about
Prompt Example:
"Refactore diese Klasse nach dem GoF-Strategy Pattern, um die verschiedenen Berechnungsarten austauschbar zu machen."
Related Anchors:
-
GoF Design Patterns (Umbrella)