User:Boldingd/Sandbox/GuiProgramming/An Overview of Design Patterns

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Design Patterns[edit | edit source]

For many readers, the techniques that we use in GUI programming might seem odd. Frequently, the reader may have used objects mainly to model the entities and structures in their code fairly directly; if we have a program that uses points, we will have a 'point' class, and its methods will be the operations that we can perform on 'points'. In contrast, in GUI programming, we will frequently use language features to achieve organizational and structural ends; we will build classes that are designed to be composed into trees, or designed to contain instances of other classes, or perform other purely 'structural' ends.

Many of these structural techniques are in fact not unique to GUI programming; they are in fact common techniques. There are some organizational problems that are common; they recur frequently in different programs. For some of these common problems, software engineers have developed schematic common solutions; we call these 'design patterns'.

Many of the organizational techniques that we use in GUI programming are in fact instances of general design patterns; it may be to the reader's general benefit to discuss these patterns in a general context.

Students should consult the Wikipedia article on Software Design Patterns. Perhaps the seminal text on the subject of design patterns is the book Design Patterns.

The Compositor[edit | edit source]

We use the Compositor design pattern in the design of the BasicWidget class.

The Decorator[edit | edit source]

We use the Decorator pattern extensively in GUI toolkits; many container widgets are Decorators.

The Observer[edit | edit source]

Most toolkits use some variant of the Observer pattern to implement their event systems.