The Context delegates some work to the Strategy object instead of Public void SetStrategy(IStrategy strategy) Usually, the Context allows replacing a Strategy object at runtime. also provides a setter to change it at runtime. Usually, the Context accepts a strategy through the constructor, but work with all strategies via the Strategy interface.
Context does not know the concrete class of a strategy. The Context maintains a reference to one of the Strategy objects. The Context defines the interface of interest to clients.
Program.cs: Conceptual example using System In what way the elements of the pattern are related?.This example illustrates the structure of the Strategy design pattern. Identification: Strategy pattern can be recognized by a method that lets a nested object do the actual work, as well as a setter that allows replacing that object with a different one. It’s often used in various frameworks to provide users a way to change the behavior of a class without extending it. Usage examples: The Strategy pattern is very common in C# code.