0% found this document useful (0 votes)
35 views

Creational Design Patterns: Pattern Singleton

Singleton is one of the Gangs of Four Design patterns and comes in the Creational Design Pattern category. Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the Java virtual machine. The singleton class must provide a global access point to get the instance of the class. Singleton pattern is used for logging, driver objects, caching and thread pool. Singleton design pattern is also used in other design patterns like Abstract Factory, Builder,Prototype, Facade etc. Singleton design pattern is used in core Java classes also, for example java.lang.Runtime ,java.awt.Desktop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Creational Design Patterns: Pattern Singleton

Singleton is one of the Gangs of Four Design patterns and comes in the Creational Design Pattern category. Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the Java virtual machine. The singleton class must provide a global access point to get the instance of the class. Singleton pattern is used for logging, driver objects, caching and thread pool. Singleton design pattern is also used in other design patterns like Abstract Factory, Builder,Prototype, Facade etc. Singleton design pattern is used in core Java classes also, for example java.lang.Runtime ,java.awt.Desktop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATIONAL DESIGN PATTERNS

Creational design pattens provide solution to instantiate an object in the


best possible way for specific situations. The basic form of object creation
could result in design problems or add unwanted complexity to the design.
Creational design patterns solve this problem by controlling the object
creation by different ways. There are five creational design patterns that
we will discuss on :

Singleton Pattern
Factory Pattern
Abstract Factory Pattern
Builder Pattern
Prototype Pattern

Pattern Singleton

Pattern Singleton: > One Class, one Instance.

Singleton is one of the Gangs of Four Design patterns and comes in the
Creational Design Pattern category. Singleton pattern restricts the
instantiation of a class and ensures that only one instance of the class
exists in the Java virtual machine. The singleton class must provide a
global access point to get the instance of the class. Singleton pattern is
used for logging, driver objects, caching and thread pool. Singleton design
pattern is also used in other design patterns like Abstract
Factory, Builder,Prototype, Facade etc. Singleton design pattern is
used in core Java classes also, for
example java.lang.Runtime ,java.awt.Desktop.

To implement Singleton pattern, there are really many approaches but all
of them have following common concepts:

A private constructor to avoid instantiation of the class,


A private static variable from the same class that's the only instance
of the class.
public static method that returns the instance of the class, this is the
global access point for the outer world to get the instance of the
class.

You might also like