Author: Marinko Spasojevic

C# Design Patterns – Factory Method

The Factory method is a creational design pattern which provides an interface for creating objects without specifying their concrete classes. It defines a method which we can use to create an object instead of using its constructor. The important thing is that the subclasses can override this method and create objects of different types. In this article, we are going to show you how to implement a Factory method design pattern. Furthermore, we are going to learn how to use the Factory method refactoring technique to hide constructor and use our own method to expose it. We are going...

Read More

C# Design Patterns – Faceted Builder

In the previous two articles, we were talking about Builder Design Pattern and Fluent Builder With Recursive Generics. We recommend reading at least the first one for a better understanding of the Builder Design Pattern. The second one is the upgrade to the first article and if you want to learn more about using recursive generics with the Builder Pattern, then we recommend reading that one as well. Why do we need the Faceted Builder? Sometimes we may have a complex object, and the creational process requires more than one builder class. So, what we need to do is...

Read More

C# Design Patterns – Fluent Builder Interface With Recursive Generics

In the previous post, we have been talking about Builder and the Fluent Builder design patternsBuilder and the Fluent Builder design patterns. So, we strongly recommend reading that one before you continue with this post if you are not familiar with the Fluent Builder pattern. In this post, we are going to get a Fluent Builder to a higher level and show how we can use generics while inheriting from another Fluent Builder. When builders inherit from other builders, nothing particular is going to happen and everything should remain the same. But if one Fluent Builder inherits from another...

Read More

C# Design Patterns – Builder Design Pattern and Fluent Builder

The Builder design pattern is a creational design pattern which lets us create an object one step at a time. It is quite common to use this pattern when creating a complex object. By using this pattern, we can create different parts of an object, step by step, and then connect all the parts together. Without this pattern, we can end up with a large constructor to provide all the required parameters for constructing our object. That could lead to quite unreadable and hardly maintainable code. Furthermore, a constructor with lots of parameters has a downside to it. We won’t...

Read More

SOLID Principles in C# – Dependency Inversion Principle

The basic idea behind the Dependency Inversion Principle is that we should create the higher level modules with its complex logic in such a way to be reusable and unaffected by any change from the lower level modules in our application. To achieve this kind of behavior in our apps, we introduce abstraction which decouples higher from lower level modules. Having this idea in mind the Dependency Inversion Principle states that High-level modules should not depend on low-level modules, both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions. We are going to...

Read More