Programming Interviews Exposed: Secrets to Landing Your Next Job, 3rd Edition
by John Mongan, Eric Giguere, Noah Kindler
Common Design Patterns
The Design Patterns book by Gamma et al. (often referred to as “The Gang of Four”), takes a formal and detailed approach to describing 23 fundamental design patterns. It groups these patterns into three basic categories: creational, behavioral, and structural.
It’s well worth reading and studying design patterns as described by The Gang of Four. We can’t hope to cover in one chapter everything that others cover in volumes, but the summaries that follow provide a quick review of some common patterns.
Creational Patterns
These patterns manage class selection and object creation. Rather than creating objects directly, it may be advantageous for code to delegate object creation to other parts of an application, or to restrict how object instances can be created and accessed.
Singleton
The Singleton pattern ensures that at most one instance of a class exists at any given time. This instance acts as a gatekeeper to shared resources or as a central communications hub. An application cannot create new instances — all methods are accessed through the singleton. The application obtains the singleton by invoking a static method exposed by the class.
Core system functions are often accessed using singletons. In Java, for example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access