Singleton Pattern in Software Engineering: A Detailed Report

Verified

Added on  2023/05/31

|5
|538
|412
Report
AI Summary
This report delves into the Singleton pattern, a crucial design pattern in software engineering. It explains the pattern's core concept: restricting a class to a single instance, and its application in scenarios requiring global access and coordination, such as logging systems. The report highlights the benefits of the Singleton pattern, including ease of implementation, testing, and reusability, while also explaining its role in managing class constructors. The report further provides a code example demonstrating the implementation of the Singleton pattern, particularly focusing on the getInstance method's role in ensuring only one instance is created. References to supporting literature are also included.
Document Page
Running head: SOFTWARE ENGINEERING - SINGLETON PATTERN
Software engineering - Singleton pattern
[Name of the Student]
[Name of the University]
[Author note]
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
1SOFTWARE ENGINEERING - SINGLETON PATTERN
Singleton pattern is considered to be the software design pattern which is associated
with restricting the initiation of one class to one object. This Pattern is generally applied and
is useful when exactly one object is in in need of coordinating with the actions across the
system. This pattern is particularly used for describing the way by which the recurring design
problems can be solved so as to provide a flexible as well as reusable Object-oriented
software. This are the objects which are easy to implement, change, test and reuse (Kim et al.
2016). This pattern can help in hiding the constructers of the class and is associated with
defining a particular public static operation as (getInstance()), this in turn is associated with
returning the sole instances of the class.
Singleton pattern is generally utilized for the purpose designing the logger classes.
This are the classes which are applied as a singleton and is associated with providing global
logging access point to all the components of an application. However, it is always not
necessary that an object is created each time whenever a logging operation is performed.
For example: deployment of a static member in the singleton class, along with a private class
and a static public method is associated with returning a reference to the static member
(Uchiyama et al. 2014). The singleton pattern is associated with defining a getInstance
operation which is responsible for the exposure of the unique instance that gets accessed by
the clients.getInstance() is responsible for the creation of an unique class instance in cases
when it is not created and also for eh purpose of returning that instance. The program for
doing this have been provided below:
class Singleton {
private static Singleton instance;
Document Page
2SOFTWARE ENGINEERING - SINGLETON PATTERN
private Singleton() {
...
}
public static synchronized Singleton getInstance(){
if (instance == null)
instance = new Singleton();
return instance;
}
...
public void doSomething()
{
...
}
}
From the above code it is evident that getInstance method is associated with ensuring
the fact that only a single call is being created.
Document Page
3SOFTWARE ENGINEERING - SINGLETON PATTERN
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4SOFTWARE ENGINEERING - SINGLETON PATTERN
References:
Kim, W., Li, J., Hong, J.W.K. and Suh, Y.J., 2016, June. Ofmon: Openflow monitoring
system in onos controllers. In NetSoft Conference and Workshops (NetSoft), 2016 IEEE (pp.
397-402). IEEE.
Uchiyama, S., Kubo, A., Washizaki, H. and Fukazawa, Y., 2014. Detecting design patterns in
object-oriented program source code by using metrics and machine learning. Journal of
Software Engineering and Applications, 7(12), p.983.
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]