Exploring the Observer Design Pattern


During the course of a given development project, it is not uncommon to use the concept of design patterns to address certain problems relating to application design and architecture. However, the definition of design patterns is often difficult to convey with any level of accuracy; as such, the concept warrants a brief examination of origin and history.

The origin of software design patterns is attributed to the work of Christopher Alexander. As a building architect, Alexander noted the presence of common problems and related solutions within a given context. A design pattern, as Alexander termed this problem/solution/context triad, enabled an architect to rapidly address issues in a uniform manner during building design. First published twenty-five years ago, A Pattern Language: Towns, Buildings, Construction (Alexander et al, Oxford University Press, 1977) introduced over 250 architectural design patterns and provided the basis for the inclusion of this concept into the realm of software development.

In 1995, the software industry was first widely introduced to the design patterns as they directly related to building applications. The four authors, Gamma, Helm, Johnson, and Vlissides (collectively known as the Gang of Four, or GoF), intersected Alexander’s design patterns with the burgeoning object-oriented software movement in their work, Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Pub Co, 1995). Based on their collective experience and examination of existing object frameworks, the GoF provided 23 design patterns that examined common problems and solutions encountered while designing and architecting applications. Following that publication, the concept of design patterns has grown to encompass many problems and solutions encountered in the software domain. In fact, the popularity of design patterns has given rise to the concept of anti-patterns, which are solutions that commonly worsen, rather than solve, the problem at hand.

Why Design Patterns?

Although not a magic bullet (if such a thing exists), design patterns are an extremely powerful tool for a developer or architect actively engaged in any development project. Design patterns ensure that common problems are addressed via well-known and accepted solutions. The fundamental strength of patterns rests with the fact that most problems have likely been encountered and solved by other individuals or development teams. As such, patterns provide a mechanism to share workable solutions between developers and organizations. Regardless of where these patterns find their genesis, patterns leverage this collective knowledge and experience. This ensures that correct code is developed more rapidly and reduces the chance that a mistake will occur in design or implementation. In addition, design patterns offer common semantics between members of an engineering team. As anyone who has been involved in a large-scale development project knows, having a common set of design terms and principles is critical to the successful completion of the project. Best of all, design patterns—if used judicially—can free up your time.


Continue reading