Object-Oriented Programming

Design Patterns Introduction

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Observations

  • There are repeated design structures and roles of classes used in most software

  • Not possible to capture these structure and roles into specific classes, i.e., they are a part of a class, but do not make up the entire class

  • Language features may support these if organized correctly

  • Need a way to communicate about them

Issues

  • Must be widely applicable

  • Solution must be safe

  • Solution should be efficient

Origins

Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to that problem, in such a way that you can use the solution a million times over, without ever doing it in the same way twice

Christopher Alexander, “A Pattern Language”, 1977

Software Design Patterns

  • Design Patterns: Elements of Reusable Object-Oriented Software Gamma, Helm, Johnson, Vlissides

  • AKA, “Gang of 4 Book” (GOF’95)

Elements of Design Patterns

  • Name

  • Problem

  • Solution

  • Consequences

Pattern Categories

  • Creational Patterns

    • E.g., Factory Method
  • Structural Patterns

    • E.g., Proxy
  • Behavioral Patterns

    • E.g., Template Method