mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 20:58:35 +00:00
465a6871b2
* refactor: move tests of leader-followers into correct package * dep: remove version constraint for Mockito in acyclic-visitor * dep: remove version constraint for Mockito in caching * chore: cleanup mockito-core import on some POMs * dep: upgrade core.mocktio 3.5.6 to 4.5.1 "- org.mockito.Mockito#verifyZeroInteractions an alias of verifyNoMoreInteractions" https://github.com/mockito/mockito/commit/caf35b24e2764df0498469526ecb3e7ec68a0430
title, category, language, tags
| title | category | language | tags | |
|---|---|---|---|---|
| MonoState | Creational | en |
|
Also known as
Borg
Intent
Enforces a behaviour like sharing the same state amongst all instances.
Class diagram
Applicability
Use the Monostate pattern when
- The same state must be shared across all instances of a class.
- Typically this pattern might be used everywhere a Singleton might be used. Singleton usage however is not transparent, Monostate usage is.
- Monostate has one major advantage over singleton. The subclasses might decorate the shared state as they wish and hence can provide dynamically different behaviour than the base class.
Typical Use Case
- The logging class
- Managing a connection to a database
- File manager
Real world examples
Yet to see this.
