This article discusses the Singleton pattern in software engineering, which restricts the initiation of one class to one object. It is useful for solving recurring design problems and creating flexible and reusable object-oriented software. The article explains its implementation and usage in logger classes.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Running head: SOFTWARE ENGINEERING - SINGLETON PATTERN Software engineering - Singleton pattern [Name of the Student] [Name of the University] [Author note]
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
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;
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.
3SOFTWARE ENGINEERING - SINGLETON PATTERN
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
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. InNetSoft 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.