Design patterns are used to resolve frequent design issues in software program improvement and to scale back the complexities in our supply code. Design patterns could be creational (associated to object creation), structural (associated to object meeting), or behavioral (associated to object collaboration and separation of tasks).
The technique design sample is a Gang-of-Four (GoF) design sample. It is a behavioral sample used to outline a household of algorithms and encapsulate every of them inside a category. These encapsulated algorithms are then interchangeable — i.e., they will differ based mostly on totally different inputs, independently of the consumer that makes use of them.
In different phrases, the technique design sample decomposes implementation code into concrete courses and therefore promotes reusability. This article presents a dialogue of the technique design sample and the way it may be carried out in C#.
Strategy design sample members
The members in a typical implementation of the technique design sample embody the next:
- Strategy — used to declare a standard interface for all concrete technique sorts. The Context takes benefit of the Strategy interface to invoke an algorithm at runtime.
- ConcreteStrategy — used to implement the algorithm that’s declared within the Strategy interface.
- Context — incorporates a reference to the Strategy occasion and makes use of this reference to invoke the algorithm that’s outlined by a concrete technique kind.