Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Outline
layout title folder permalink categories tags
pattern
MonoState
monostate
/patterns/monostate/
Creational
Java
Difficulty-Beginner

Also known as

Borg

Intent

Enforces a behaviour like sharing the same state amongst all instances.

alt text

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.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.