CSC/ECE 517 Fall 2012/ch2b 2w53 iv: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 13: Line 13:


Lazy initialization uses double-checking and eager initialization which always creates an instance. It also talks about Prototype-based programming in which objects but not classes are used, a 'singleton' simply refers to an object without copies or that is not used as the prototype for any other object. Eg :-> Foo := Object clone ; Foo clone := Foo
Lazy initialization uses double-checking and eager initialization which always creates an instance. It also talks about Prototype-based programming in which objects but not classes are used, a 'singleton' simply refers to an object without copies or that is not used as the prototype for any other object. Eg :-> Foo := Object clone ; Foo clone := Foo
'''Drawbacks''' :
The pattern makes unit testing far more difficult as it introduces global state into an application. It should also be noted that this pattern reduces the potential for parallelism within a program, because access to the singleton in a multi-threaded context must be serialized.
2. http://www.c-sharpcorner.com/UploadFile/SukeshMarla/learn-design-pattern-singleton-pattern/
'''Topics Covered''' :
Definition, When to use, how to create, Sharing across all users, Sharing across a request, Sharing across a single user
'''Summary''' :
This article explains what Singleton pattern is, what kind of problem it generally solves and how should it be implemented in ASP.NET. The Singleton pattern which ensures that only one instance of a given object can exist at a context solves problems related to object creation and hence is a type of creational pattern.
It can be used in a class that wraps the settings related to an application. In other words, whenever we want something to be shared across multiple locations, we use a singleton pattern. In order to create a Singleton pattern, we can render the constructor private so that no user can create a new instance outside the class, that way ensuring only one instance of the objects always exists. In that case, we also need to create a static method that returns the single object.
Singleton patterns in ASP.NET are implemented by using static objects which maintain their values and reside in the memory as long as the application which contains it does. The sharing can occur across users, or requests or across a single user.
3. http://www.c-sharpcorner.com/UploadFile/faraz.rasheed/SingletonPattern12052005063955AM/SingletonPattern.aspx
'''Topics Covered''' :





Revision as of 23:56, 17 November 2012

Singleton, directory of sites

Singleton, directory of sites Pattern

1. http://en.wikipedia.org/wiki/Singleton_pattern

Topics Covered : Common uses, UML, Implementation, Example, Prototype based singleton, Example of use with factory method pattern

Summary : This link firstly provides the basic definition of the singleton pattern as a design pattern that restricts the instantiation of a class to one object. Singleton patters are mostly used in Abstract Factory, Builder, and Prototype, and Facade patterns.

Both the UML representation of singleton where the same single instance is always returned and the implementation concerning the mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among the class objects. The link also points out that if a class has to realize a contract expressed by an interface, it really has to be a singleton.

Lazy initialization uses double-checking and eager initialization which always creates an instance. It also talks about Prototype-based programming in which objects but not classes are used, a 'singleton' simply refers to an object without copies or that is not used as the prototype for any other object. Eg :-> Foo := Object clone ; Foo clone := Foo

Drawbacks : The pattern makes unit testing far more difficult as it introduces global state into an application. It should also be noted that this pattern reduces the potential for parallelism within a program, because access to the singleton in a multi-threaded context must be serialized.

2. http://www.c-sharpcorner.com/UploadFile/SukeshMarla/learn-design-pattern-singleton-pattern/

Topics Covered : Definition, When to use, how to create, Sharing across all users, Sharing across a request, Sharing across a single user

Summary : This article explains what Singleton pattern is, what kind of problem it generally solves and how should it be implemented in ASP.NET. The Singleton pattern which ensures that only one instance of a given object can exist at a context solves problems related to object creation and hence is a type of creational pattern.

It can be used in a class that wraps the settings related to an application. In other words, whenever we want something to be shared across multiple locations, we use a singleton pattern. In order to create a Singleton pattern, we can render the constructor private so that no user can create a new instance outside the class, that way ensuring only one instance of the objects always exists. In that case, we also need to create a static method that returns the single object.

Singleton patterns in ASP.NET are implemented by using static objects which maintain their values and reside in the memory as long as the application which contains it does. The sharing can occur across users, or requests or across a single user.

3. http://www.c-sharpcorner.com/UploadFile/faraz.rasheed/SingletonPattern12052005063955AM/SingletonPattern.aspx

Topics Covered :


\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

<references />