Singleton Concept in Object Oriented ABAP

Working with singleton design patterns in Object oriented ABAP, Singleton class in OOABAP

+ -

Sometimes in the real-time business scenarios, we need to have only one instance for a class at a point of time, for this one we have the concept of singleton in ABAP objects.

Singleton pattern : is the one of the simplest design patterns which involves only one class which instantiates itself to make sure that it creates one instance.Singleton ensues that it has only one instance and provides global point of access to the object.

Example - Logger Classes

The Singleton pattern is used in the design of logger classes. This classes are usually implemented as a singletons, and provides a global logging access point in all the application components without being necessary to create an object each time a logging operations is performed.

Steps to be followed to create singleton class

  • Create a private class.
  • Add a private attribute with reference to the same class.
  • Create a public static method with returning value of type reference to same class.
  • Create implementation and create object in the implementation of public static method.
  • Call static method in any program to create instance for the singleton class.
In the next lesson we will be learning how to create singleton class.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 30 People out of 31 think this lesson helpful


    Lesson Navigation

    ALV Factory Method with OOABAP← Previous Lesson
    Next Chapter →