Singleton Pattern – OOABAP
The concept of restricting the instantiation of the a class to only one object is called Singleton. This is useful when exactly one object is needed to coordinate actions across the system.
Read about Singleton Pattern
SingleObject class provides a static method to get its static instance to outside world. SingletonPatternDemo, our demo class will use SingleObject class to get a SingleObject object.
Let’s try this pattern in ABAP program:
I have retrieved the singleton instance, set a value to private attribute, retrieved it back and showed it to the user..
If I try to get instance again, it returns the existing one..
After executing the report, below will be output: