Home / cs-notes / Design / Design Patterns / Creational Patterns / Singleton
Singleton
Solution
- Simple
@startuml
class Singleton {
- instance: Singleton {static}
- Singleton()
+ getInstance(): Singleton {static}
}
@enduml
- Inner Class
@startuml
class Singleton {
- Singleton()
+ getInstance(): Singleton {static}
}
-class InstanceHolder {
- instance: Singleton {static}
}
Singleton +. InstanceHolder
@enduml
- Enumeration
@startuml
enum Singleton {
+ INSTANCE {static}
}
@enduml
Issues
- Thread Safe
- volatile
- synchronized
- Uniqueness
- Class Load
- Clone
- Reflect
- Deserialize