Showing posts with label Design patterns. Show all posts
Showing posts with label Design patterns. Show all posts

June 30, 2012

Singleton pattern

I'm sorry for pause in writing new posts about design patterns.  
Unfortunately, I had no free time, but now I'm really ready to do it.

So, today I'm going to write a post about the most popular and well-known design pattern - Singleton.

The essence of Singleton is to provide :
  • exactly one instance of class across the system;
  • simple access to it.
The implementation of Singleton based on creation a class with a method(or property in .NET) that creates an instance of this class if one doesn't exists yet. The constructor of class must be private to prevent other ways of initialization. Also Singleton must be carefully used in multi-threaded applications because in one point of time, the two threads may create two different instances (which violates singleton pattern).

Below I'll explore the most frequent implementations of pattern. As always, I'll show structural code and real-world code.

June 9, 2012

Facade pattern


First pattern which I'll try to explore is a structural pattern - Facade.

Before we go to the pattern I think we must understand a concept of subsystem.

Subsystem is a part of large system that consists of a set of elements and relations.
Let's look for simple example for better understanding.


Here you can see a system which consists of four subsystems : UserInterface, OrderManagement, SeatingManagement and Database. Each subsystem has own logic as well as relations to another subsystem(s).

June 7, 2012

Structure of design patterns


From wikipedia :
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.

I always wanted to write all well-known design patterns into one repository with details and own examples. I think that my blog and github (all sources will be avaible on github) is comfortable for it.
So, every Saturday I'll be write a post about exactly one design pattern.

In this post, I want to group the design patterns into the categories.
Historically, design patterns were grouped into : creational patterns, structural patterns, and behavioral patterns.

From each group I chose only most popular and well-known patterns.