Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum Types
- {
- Type1,
- Type2,
- Type3,
- Type4
- }
- public interface IStrategy
- {
- Types Type { get; }
- void Do();
- }
- public class Realization1 : IStrategy
- {
- public Types Type => Types.Type1;
- public void Do()
- {
- Console.WriteLine(Type.ToString());
- }
- }
- public class Realization2 : IStrategy
- {
- public Types Type => Types.Type2;
- public void Do()
- {
- Console.WriteLine("Result = " + Type.ToString());
- }
- }
- public class MainRealization
- {
- private readonly IEnumerable<IStrategy> _strategies;
- public MainRealization(IEnumerable<IStrategy> strategies)
- {
- this._strategies = strategies;
- }
- public void Do(Types requiredType)
- {
- var method = this._strategies.FirstOrDefault(x => x.Type == requiredType);
- method.Do();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement