...  7	public static void main(String[] args)
8	{
9		Singleton firstSingleton;
10		Singleton secondSingleton;
11
12		// create Singleton objects
13		firstSingleton = Singleton.getInstance();
14		secondSingleton = Singleton.getInstance();
15
16		// the "two" Singletons should refer to same Singleton
17		if (firstSingleton == secondSingleton)
18			System.err.println("firstSingleton and secondSingleton " +
19			"refer to the same Singleton object");
20	} // end main
21 } // end class SingletonTest

Computer code and its output.

N.2.2 Structural Design Patterns

Structural design patterns describe common ways to organize classes and objects in a system. The Gang-of-Four ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.