Author: Marinko Spasojevic

C# Design Patterns – Adapter

The Adapter design pattern is a creational pattern which allows incompatible interfaces to work together. By doing so, we allow objects from different interfaces to exchange data. In this article, we are going to learn how to implement the Adapter pattern into our project and when should we use it. Builder Design Pattern and Fluent Builder Fluent Builder Interface With Recursive Generics  Faceted Builder  Factory Method  Singleton  Adapter (Current article) Composite Decorator Command Strategy This article is part of the series The source code is available at the Adapter Design Pattern – Source Code. For the main page of this...

Read More

C# Design Patterns – Singleton

The Singleton is a creational design pattern which allows us to create a single instance of an object and to share that instance with all the users that require it. There is a common opinion that the Singleton pattern is not recommended because it presents a code smell, but there are some cases where it fits perfectly. For example, some components have no reason to be instanced more than once in a project. Take a logger for example. It is quite common to register logger class as a singleton component because all we have to do is to provide...

Read More

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. Builder Design Pattern...

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. Builder Design Pattern and Fluent Builder Fluent Builder Interface With Recursive Generics  Faceted Builder (Current article) Factory Method Singleton Adapter Composite Decorator Command Strategy This article is part of the series...

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 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 one, well, we are going to...

Read More