-
Notifications
You must be signed in to change notification settings - Fork 0
Design Pattern
jlai edited this page Sep 12, 2022
·
4 revisions
The singleton pattern is a way to make sure
that a class has only one instance
and it provides a single point of access to it.
The pattern specifies that the class should be responsible it self
for keeping track of its sole instance.
It can further ensure that no other instance can be created by intercepting
requests for creating new objects and provide a way to access the sole instance.
- Data inconsistency
- Hidden dependencies
- Untestable code
- Breaks SOLID
- Do need exactly one instance of that class, and creation of second instance can be dangerous
- Each class should have only one responsibility
- Class should be opened for extension but closed for modification
- Open for extension
- Closed for modification
- Child class should not break the parent class type definitions
- Implement only what you need
- Depend on abstractions, not on concretions