MSc-IT Study Material
January 2011 Edition

Computer Science Department, University of Cape Town
| MIT Notes Home | Edition Home |

Introduction to design patterns

The idea of a pattern

A bridge is a structure used for traversing a chasm. In its basic form it consists of a beam constructed of rigid material, the two ends of the beam fixed at opposite ends of the chasm.

Figure 8.1. A simple pattern for a bridge

A simple pattern for a bridge

The bridge will fulfil its function if the rigidity of the beam can support the loads which traverse it. The beam's rigidity depends on the material of its construction and its span. In situations where the heaviness of the load, the length of the span or the material of construction are likely to lead to failure, the design of the bridge needs to be modified. More rigid materials are generally more expensive and/or more difficult to work with, so we shall ignore this possibility. This leaves two possible approaches:

  1. Increasing the rigidity.

  2. Decreasing the span.

Increasing the rigidity

The rigidity of the bridge structure can be improved by supporting the beam in a number of ways.

The girder

We can redistribute the beam's material to improve its rigidity.

Figure 8.2. The girder

The girder

Some of the force of the load on the lower beam is distributed by the cross-members resulting in a compressive force in the upper beam. The (same) material of construction of the upper beam is better able to support compressive forces along its length.

The arch

Some of the force of the load on the beam is distributed compressively along the material of the arch.

Figure 8.3. The arch

The arch

The arch must be specially shaped so that the forces remain compressive along the length of the arch. This shape is called a catenary.

Suspension

The arch can be replaced by a cable which supplies the same support from above rather than below.

Figure 8.4. Suspension

Suspension

The cable hangs in a catenary shape.

Decreasing the span

If the chasm is not too deep it may be possible to divide it into two sub-chasms by building a support in the middle.

Figure 8.5. Subdivision

Subdivision

Alternatively, the edges of the chasm can be extended to reduce the length of the span.

Figure 8.6. Narrowing

Narrowing

Some bridges are built by combining several of these approaches into and elegant and functional structure.

Figure 8.7. The Forth Bridge

The Forth Bridge
The Forth Bridge is a railway bridge over the Firth of Forth river in Scotland.

Patterns

These are the patterns of bridge design. Even though we have no specialist knowledge of civil engineering, we can see how and why they work, and when we look at a bridge we can see the patterns which were used to design it because they are built into its structure. Civil engineers, whose work is to build such bridges, learn these patterns along with a great deal of specialised knowledge about construction materials and very sophisticated analytical techniques which help them to make precise predictions about the strength and suitability of different designs and materials before the bridges are built. They use the patterns, either singly or in combination, when thinking about and discussing the design of a particular bridge with other engineers, and they recognise the patterns used in constructing the bridges of their fellow engineers.

The origins of design patterns

The ideas behind design patterns come not from civil engineers but from architects. Like civil engineers, architects are concerned with designing structures to meet certain functional requirements. Individual buildings need to have a form that helps them to fulfil their purpose. For instance, a dwelling for a single family needs to have a living area, a sleeping area and utility rooms, like a kitchen and a bathroom. A good dwelling design will place these together in such a way that makes family living convenient and pleasant. The sleeping area should be away from the living area so that it is quiet. The bathroom will be directly accessible from many parts of the house, and not, for example, via one of the bedrooms. The kitchen should be accessible from the living area but not from the sleeping area. In addition, the design will make efficient, effective and economic use of the materials of construction, for example roofing, materials and plumbing.

In their working lives architects solve these problems over and over again, in slightly different ways and under different circumstances. However, the basic precepts of good dwelling design remains the same, and they are different from the precepts of good office block design, or good hotel design or good hospital design. The design patterns of architects are the solutions they have found to all these various problems. Like civil engineers, architects can see the patterns in the buildings they design and see examples in the designs of other architects every time they walk into a house or drive down a street.

In the 1970's the architect Christopher Alexander wrote a series of books in which he first enunciated the idea of the design pattern, and the ways in which patterns could be used to solve specific architectural problems, and be combined to communicate design ideas amongst architects. He said:

 

Each pattern is a rule which describes what you have to do to generate the entity which it defines.

 
 -- Christopher Alexander, The Timeless Way of Building

This definition gives a pattern two roles – firstly, as an abstract description of a solution to a particular type of problem; and secondly as a form which we can recognise within an entity which solves the problem. Thus a suspension cable is a way of providing support to the beam of a bridge, and when we look at a bridge we can see whether or not it uses a cable for support.

Patterns in software design

Many aspects of the work of software engineers have parallels with the work of civil engineers and architects. For instance:

  • Software engineers design and construct software systems to meet certain functional requirements.

  • These software systems may consist of a number of software components which must work together in a structure to deliver the functions.

  • The designers must concern themselves with effective, efficient and economic construction and operation.

  • There are precepts of good design for various types of software system.

  • Software engineers solve variations of particular design problems over and over again.

However, there are also some stark differences.

  • Although they may use other engineers' software, software engineers rarely have the opportunity to observe other people's software designs in the same intimate way that an architect can when he or she enters a building.

  • Both civil engineering and architecture are very old disciplines stretching back thousands of years. In contrast, software engineering is a new discipline, only a few decades old.

It is not surprising that software engineers would look to more mature design disciplines for some assistance in defining what they were trying to do and in a search for techniques to help them to do it. As explained in Chapter 2, Process and Model, the term software engineering itself was coined to emphasise the belief that it took more than just skillful programming to produce a good piece of software, and that careful consideration of requirements combined with systematic design and development would help to bring software artefacts up to the same levels of reliability and elegance as well-engineered hardware.

The work of Alexander was known to two software engineers, Ward Cunningham and Kent Beck, when, in 1987, they visited a client to discuss the design of a user interface. They liked Alexander's idea that a pattern is a symbolic way of describing a solution to a type of problem, and that a set of patterns could provide a language for discussing the problem and considering various solutions. They wanted the users of the proposed system to contribute to the design (another Alexandrian precept), so they invented a small set of user interface patterns for their users. They became convinced of the value of these ideas and their relevance to software engineering when the users produced a very elegant and efficient design using the simple pattern language.

Ward and Cunningham presented their conclusions at a software engineering conference (OOPSLA '87) but few of the delegates were convinced. However, at about the same time, other workers in software engineering were feeling their way towards an architectural view of software engineering and by the 1991 OOPSLA conference the term design patterns was in use. A community of software engineers was gradually developing who were taking Alexander's work very seriously. Many of the leading members of this community attended a meeting in 1993. During the meeting, they decided to try designing a building according to Alexander's principles. This included laying out the physical building plan, which they duly did on the side of the hill in Colorado where the meeting was being held. Henceforth, they were known as the Hillside group.

Finally, in 1995, four of the main proponents of design patterns, E. Gamma, R. Helm, R. Johnson and J. Vlissides published the first book on design patterns, Design Patterns: Elements of Reusable Object-Oriented Software. This is still perhaps the most authoritative book on the subject and much of the ensuing material is drawn from there. The four authors are known in the design pattern community as The Gang of Four.