You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Strategy Pattern defines a family of algorithms, encapsulates each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
3
+
The Strategy Pattern
4
+
* defines a family of algorithms,
5
+
* encapsulates each one, and
6
+
* make them interchangeable.
7
+
Strategy lets the algorithm vary independently from clients that use it.
8
+
9
+

10
+
11
+
**Usage**
12
+
```cs
13
+
Duckmallard=newMallardDuck();
14
+
mallard.PerformQuack();
15
+
mallard.PerformFly();
16
+
17
+
// change the flying behavior dynamically
18
+
Duckmodel=newModelDuck();
19
+
model.PerformFly(); // default behavior
20
+
model.FlyBehavior=newFlyRocketPowered(); // set a different flying behavior at runtime
21
+
model.PerformFly();
22
+
```
23
+
24
+
25
+
## Common Structure
26
+
27
+

28
+
29
+
* Strategy (SortStrategy)
30
+
* declares an interface common to all supported algorithms. Context uses this interface to call the algorithm defined by a ConcreteStrategy
0 commit comments