Uniot Core
0.8.1
Loading...
Searching...
No Matches
Singleton

Template class implementing the Singleton design pattern. More...

Collaboration diagram for Singleton:

Classes

class  uniot::Singleton< Derived >
 

Detailed Description

Template class implementing the Singleton design pattern.

The Singleton template ensures that a class has only one instance and provides a global point of access to it. This implementation uses the Curiously Recurring Template Pattern (CRTP) where the derived class passes itself as a template parameter.

Template Parameters
DerivedThe class that will become a Singleton

Usage example:

class MyClass : public Singleton<MyClass> {
friend class Singleton<MyClass>; // Required to allow construction
private:
MyClass() = default; // Constructor is private
public:
void doSomething() { ... }
};
// Access the singleton instance
MyClass::getInstance().doSomething();