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

What is Abstract Factory Pattern ?

Abstract Factory Pattern is type of Creational pattern . This is used to create objects of related class without specify concrete class.

Abstract Factory has :
 1) Abstarct Factory - declares an interface for operations that create abstract product objects.

 2) Concrete Factory - implements the operations to create concrete product objects.
 3) Abstract Product - declares an interface for a type of product object.
 4) Concrete Product - defines a product object to be created by the corresponding concrete factory. It implements the Abstract Product interface.
 5) Client - uses only interfaces declared by Abstract Factory and Abstract Product classes.

What is singleton design pattern ?

Singleton design pattern is type of Creational Design pattern . It creates a single instance object which caters to all the clients.

Singleton Design pattern has :

  1. It has private constructor so that instance of class cannot be created anywhere but inside its own methods.
  2. It has static read only member so that instance is created only once .
  3. It has an instance property to return singleton object instance
 Code snippet for simple singleton :
public sealed class Singleton
{
// private constructor
private Singleton()
{
}
// static readonly member
static readonly Singleton instance = new Sinleton();
// static instance property
public static Singleton Instance
{
get { return instance ; }
}

}

Popular Posts