diff --git a/observer/README.md b/observer/README.md index 6b8a700771f3..257e883e3040 100644 --- a/observer/README.md +++ b/observer/README.md @@ -174,6 +174,7 @@ Use the Observer pattern in any of the following situations: * When an abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently. * When a change to one object requires changing others, and you don't know how many objects need to be changed. * When an object should be able to notify other objects without making assumptions about who these objects are. In other words, you don't want these objects tightly coupled. +* This pattern is especially useful in event-driven systems where changes in one object need to be automatically reflected in multiple dependent objects. ## Real-World Applications of Observer Pattern in Java diff --git a/singleton/README.md b/singleton/README.md index 92505061399e..484b8808b953 100644 --- a/singleton/README.md +++ b/singleton/README.md @@ -78,6 +78,7 @@ Use the Singleton pattern when * Configuration classes in many applications * Connection pools * File manager +* Database connection management systems to ensure a single shared instance across the application * [java.lang.Runtime#getRuntime()](http://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#getRuntime%28%29) * [java.awt.Desktop#getDesktop()](http://docs.oracle.com/javase/8/docs/api/java/awt/Desktop.html#getDesktop--) * [java.lang.System#getSecurityManager()](http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getSecurityManager--) diff --git a/singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java b/singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java index fc89ab312dd5..558a0610b2ce 100644 --- a/singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java +++ b/singleton/src/main/java/com/iluwatar/singleton/IvoryTower.java @@ -24,7 +24,10 @@ */ package com.iluwatar.singleton; -/** Singleton class. Eagerly initialized static instance guarantees thread safety. */ +/** + * Singleton class. Eagerly initialized static instance guarantees thread + * safety. + */ public final class IvoryTower { /** Private constructor so nobody can instantiate the class. */ @@ -43,6 +46,11 @@ private IvoryTower() { * * @return instance of the singleton. */ + + /** + * Returns the single instance of IvoryTower. + * Ensures that only one instance exists throughout the application. + */ public static IvoryTower getInstance() { return INSTANCE; }