Singleton Pattern   «Prev  Next»
Lesson 2The elements of a pattern
ObjectiveUnderstand how Design Patterns can solve Problems.

Elements of Design Pattern, Intent, Motivation, Applicability, Structure

Design patterns themselves follow a pattern (a "meta-pattern," if you will). Each pattern has:
  1. The intent states the problem that the pattern addresses
  2. The motivation is a scenario that illustrates the problem
  3. The applicability of a pattern describes the circumstances under which the pattern is appropriate; that is, when you should and shouldn't use it.
  4. The structure of a pattern is normally displayed as some sort of object or class diagram.
  5. The participants in the pattern are the classes and objects that comprise it. Each class or object also has a list of responsibilities.
  6. The collaborations describe how classes and objects outside the pattern interact with the pattern.
  7. Consequences are the results of choosing a pattern, both positive and negative
  8. The implementation of a pattern is a set of code that uses the pattern. It shows the details and tricks that are needed to make it work
  9. The known uses section of a design pattern describes some object-oriented systems where the pattern is found. This provides some practical real-world examples you can use to get a closer grasp of the pattern.
  10. Lists other design patterns that are closely related.

Programming by Contract

Encapsulation makes it possible to produce dramatically more reliable code than the traditional programming style in which every function was able to modify data fields. Once we ensure that all constructors of a class create only objects with valid state and that all mutator operations preserve the valid state, then we can never have invalid objects. No operation should waste a lot of time checking for invalid objects. Bertrand Meyer, the pioneering designer of the Eiffel language, uses the metaphor of a contract to describe these guarantees. This chapter explores the ideas surrounding the concepts of programming by contract.

We all know the value of design experience. How many times have you had the feeling that you have solved a problem before but not knowing exactly where or how? If you could remember the details of the previous problem and how you solved it, then you could reuse the experience instead of rediscovering it. However, we do not do a good job of recording experience in software design for others to use.
Each design pattern systematically names and evaluates an important and recurring design in object-oriented systems. Our goal is to capture design experience in a form that people can use effectively. To this end gofpatterns.com has documented some of the most important design patterns and presents them as a catalog.
Design patterns make it easier to reuse successful designs and architectures. Expressing proven techniques as design patterns makes them more accessible to developers of new systems. Design patterns help you choose design alternatives that make a system reusable and avoid alternatives that compromise reusability. Design patterns can even improve the documentation and maintenance of existing systems by furnishing an explicit specification of class and object interactions and their underlying intent. Put simply, design patterns help a designer get a design "right" faster.

Design Pattern Elements

The following discusses the elements of design patterns.
Design Pattern Elements