OOP is considered by many to be the crown jewel of computer science. The ultimate solution to code organization. The end to all our problems. The only true way to write our programs. Bestowed upon us by the one true God of programming himself…
A strategy design pattern is the most commonly used design pattern in computer programming. In this post, we’ll refactor a switch case into a strategy design pattern. We’ll start with a basic switch case statement and then we’ll gradually refactor the code into strategy design pattern.
The Strategy design pattern is a behavioral design pattern which allows us to define different functionalities, put each functionality in a separate class and make their objects interchangeable. In other words, we have a main Context object that holds a reference towards a Strategy object and delegates it by executing its functionality. If we want to change the way the Context performs its work, we can just replace the current Strategy object with another one.
The Command pattern is a behavioural design pattern that we can use to turn a request into an object which contains all the information about the request. The Command design pattern is quite popular in C#, especially when we want to delay or queue a request’s execution or when we want to keep track of our operations. Furthermore, this possibility to keep track of our operations gives us the opportunity to undo them as well.
In this article, we are going to talk about another structural C# design pattern, the Decorator Design Pattern. We are going to learn, how to implement this pattern in our project and what we can get by doing that. The source code is available at the Decorator Design Pattern – Source Code.
Let's look at some different ways you could implement the strategy pattern in C#. First, I'd like to briefly mention why we care about design patterns and where the strategy pattern fits in. Why Should I Know The Strategy Pattern? Understanding design patterns is a vital skill to possess as a software developer and/or software architect. If you don't, then you end up
In object-oriented programming, State Pattern is one of the ways to implementFinite State Machines. This pattern falls underBehavioral Design Patterns.When in our software, an object can change betw...