C# – Pass in a Func to override behavior

If I want to change the behavior of a method from the outside, I can pass in a function pointer. This approach exists in every language, and is one way to implement the Strategy Pattern. In C#, function pointers are referred to as delegates, and the two most common ones are Action and Func. The … Read more

Refactoring the Switch Statement code smell

The Switch Statement code smell refers to using switch statements with a type code to get different behavior or data instead of using subclasses and polymorphism. In general, it looks like this: This switch(typeCode) structure is typically spread throughout many methods. This makes the code difficult to extend, and violates the Open-Closed Principle. This principle … Read more