Introduction
The idea of design patterns is not new. Ever since there were engineers, design patterns have existed. The architects of the great pyramids must have used design patterns to envision and eventually build one of the most durable testimonies to quality engineering.
So what are design patterns? Simply put, design patterns name and describe effective solutions for common design problems. The name of a pattern gives us a common term that may be used when discussing design solutions. The description provides a guideline or template that can be applied to a frequently occurring design problem.
Background
Actually you dont need any backgroud in this kind of stuff because the Design Pattern is nothing just some experience of other guys!
Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges. The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral.
strictly speaking,With Design pattern you will not wish to invent the wheel again,although you would use them for creating most efective apllications.In this Article I will explain what Singleton design pattern is and how to implement that.now That's upon you to choose where to use That!
Come on Let whine to up!
Using the code
Ok What is Singleton pattern.As its name imply it has to do with somthing "single"!.This design pattern is categoried in "Creation Patteren" and it's intention is to ensure that we can create just one object from our desired class.So due to this all our needs would wrap to this object.
Actually this object does the whole work as a common and One object.So now lets look at some codes:
public class SingletonPattern
{
SingletonPattern() { }
class SingletonCreator
{
static SingletonCreator() { }
internal static SingletonPattern OneInstance = new SingletonPattern();
}
public static SingletonPattern ONEInstance
{
get
{
return SingletonCreator.OneInstance;
}
}
public void Foo()
{
MessageBox.Show("I have created just Once!");
}
}
I have used Lazy instantiation.What is "Lazy instantiation" any way?
It means until the first Invokation, no object would be instantiate.You are also able to use "static" fields for Lazy instantiation because they also use the concept of Lazy ins...
So Guys I hope you get what Singleton pattern would be.Any feedback would be appreciated.Happy Coding!
Points of Interest
I am now workin and trying hard to increase my object oriented and design pattern knowledge.If anybody knows any helpfull areas in this kind of fields please share that.