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, ...
Get Programming Interviews Exposed: Secrets to Landing Your Next Job, 3rd 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.