Click here to Skip to main content
15,897,334 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: singleton pattern example Pin
led mike5-Sep-07 6:24
led mike5-Sep-07 6:24 
GeneralRe: singleton pattern example Pin
Urs Enzler5-Sep-07 7:04
Urs Enzler5-Sep-07 7:04 
GeneralRe: singleton pattern example Pin
led mike5-Sep-07 7:27
led mike5-Sep-07 7:27 
GeneralRe: singleton pattern example Pin
Urs Enzler5-Sep-07 7:51
Urs Enzler5-Sep-07 7:51 
GeneralRe: singleton pattern example Pin
led mike5-Sep-07 8:07
led mike5-Sep-07 8:07 
GeneralRe: singleton pattern example Pin
Urs Enzler5-Sep-07 20:19
Urs Enzler5-Sep-07 20:19 
AnswerRe: singleton pattern example Pin
hotcodeking5-Sep-07 1:58
hotcodeking5-Sep-07 1:58 
AnswerRe: singleton pattern example [modified] Pin
ElSpinos13-Sep-07 23:00
ElSpinos13-Sep-07 23:00 
Greetings Shakeela,

The Singleton design pattern serves to describe an implementation that restricts instantiation of a class to one object, in other words no copies or additional references. I've created a Singleton instantiate for you here to experiment with and get an idea of my description above. the singleton design pattern also belongs to the Creational Patterns group which consist of the following additional design patterns:

o Abstract factory pattern: centralize decision of what factory to instantiate
o Factory method pattern: centralize creation of an object of a specific type choosing one of several implementations
o Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations
o Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed
o Object pool: avoid expensive acquisition and release of resources by recycling objects that are no longer in use
o Prototype pattern: used when the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) is prohibitively expensive for a given application

The singleton class you can experiment with:
<br />
 /// <typeparam name="Type">Any type with a public and parameterless constructor.</typeparam><br />
 public sealed class SingletonCreator<Type> where Type : class, new()<br />
 {<br />
<br />
  #region Private declarations<br />
  /// <summary><br />
  /// The instance to retain after creation<br />
  /// </summary><br />
  private static Type instance;<br />
  #endregion<br />
<br />
  #region Properties<br />
  /// <summary><br />
  /// A lazy instance instantiator property.  It will test for the existence of an object and return that reference otherwise it will create a new object.<br />
  /// </summary><br />
  /// <returns>An singleton instance of type "Type".</returns><br />
  public static Type GetInstance()<br />
  {<br />
   lock (typeof(Type))<br />
   {<br />
    if (instance == null)<br />
    {<br />
     instance = new Type();<br />
    }<br />
    return instance;<br />
   }<br />
  }<br />
  #endregion<br />
<br />
 }<br />

Usage:
<br />
// This will always create an instance it it doesn’t exist or return the <br />
// existin reference if it was previously called.<br />
MyClass myClass = SingletonCreator<MyClass>.GetInstance();<br />


I hope this helps you in your quest to learn design patterns Wink | ;) Have an awesome weekend...

Fernando Mendes
Senior .NET Developer, Architect

AnswerRe: singleton pattern example Pin
etkid8421-Sep-07 3:02
etkid8421-Sep-07 3:02 
QuestionApplications communication Pin
Yoav Zur28-Aug-07 19:18
Yoav Zur28-Aug-07 19:18 
AnswerRe: Applications communication Pin
led mike30-Aug-07 4:43
led mike30-Aug-07 4:43 
QuestionClass design help Pin
rsaint2727-Aug-07 3:18
rsaint2727-Aug-07 3:18 
GeneralRe: Class design help Pin
Paul Conrad27-Jan-08 7:12
professionalPaul Conrad27-Jan-08 7:12 
QuestionPromotion Table Schema Design Pin
yameen26-Aug-07 3:48
yameen26-Aug-07 3:48 
GeneralRe: Promotion Table Schema Design Pin
Paul Conrad27-Jan-08 7:13
professionalPaul Conrad27-Jan-08 7:13 
Questiongetting infragistics Pin
starist24-Aug-07 9:28
starist24-Aug-07 9:28 
AnswerRe: getting infragistics Pin
Mark Churchill2-Sep-07 19:11
Mark Churchill2-Sep-07 19:11 
GeneralRe: getting infragistics Pin
TAHIR MURAD3-Sep-07 1:06
TAHIR MURAD3-Sep-07 1:06 
GeneralRe: getting infragistics Pin
originSH3-Sep-07 23:36
originSH3-Sep-07 23:36 
QuestionFault Exception Error Pin
Revathij23-Aug-07 1:29
Revathij23-Aug-07 1:29 
QuestionState Machine Diagram for client-server communication Pin
DotNet.Agrawal21-Aug-07 23:21
DotNet.Agrawal21-Aug-07 23:21 
AnswerRe: State Machine Diagram for client-server communication Pin
Dave Kreskowiak24-Aug-07 6:47
mveDave Kreskowiak24-Aug-07 6:47 
QuestionCreating sequential numbering in a semi-connected environment Pin
francoisdotnet17-Aug-07 21:23
francoisdotnet17-Aug-07 21:23 
AnswerRe: Creating sequential numbering in a semi-connected environment Pin
Mark Churchill19-Aug-07 15:14
Mark Churchill19-Aug-07 15:14 
GeneralRe: Creating sequential numbering in a semi-connected environment Pin
francoisdotnet19-Aug-07 20:35
francoisdotnet19-Aug-07 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.