2015-10-04 03:06:11 +05:30
---
layout : pattern
title : MonoState
folder : monostate
permalink : /patterns/monostate/
categories : Creational
2015-12-28 15:52:44 +02:00
tags :
- Java
- Difficulty-Beginner
2015-10-04 03:06:11 +05:30
---
2016-01-03 21:14:30 +01:00
## Intent
Enforces a behaviour like sharing the same state amongst all instances.
2015-10-04 03:06:11 +05:30

2016-01-03 21:14:30 +01:00
## Applicability
Use the Monostate pattern when
2015-10-04 03:06:11 +05:30
* The same state must be shared across all instances of a class.
2015-10-09 23:20:58 +05:30
* Typically this pattern might be used everywhere a Singleton might be used. Singleton usage however is not transparent, Monostate usage is.
2015-10-04 03:06:11 +05:30
* 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.
2016-01-03 21:14:30 +01:00
## Typical Use Case
2015-10-04 03:06:11 +05:30
* the logging class
* managing a connection to a database
* file manager
2016-01-03 21:14:30 +01:00
## Real world examples
2015-10-04 03:06:11 +05:30
Yet to see this.