Pages

Sunday, October 27, 2013

2. Design Pattern - Singleton Design Pattern


2.1 Introduction 

Singleton design pattern one of the mostly used and simplest pattern in java. This patterns provides the best way to create the objects.

This pattern comes under the creational pattern type.

"This pattern involves a single class which is responsible to creates own object while making sure that only single object get created. This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class."


2.2. Implementation

Here is the implementation diagram for singleton pattern.

Singleton class has three methods suchs as, getinstance(), sayHi() and clone. Getinstance method provides gives instance of the class to calling class. 

Let see the code,

SingletonClass.java


 SingletonMain.Java




Output:





No comments:

Post a Comment