Lecture Notes for Advanced Programming II

25 January 2001 - The Bridge Object Pattern


  1. consider the bag data structure - like a set but with multiple elements

    1. operations - add, get, member, count, clear

  2. possible implementations

    1. array - simple and fast, but fixed

    2. linked list - not so simple or fast, but dynamic

    3. hash table - hard, but fast (usually) and dynamic

  3. from this get the usual inheritance hierarchy

    1. class Bag

    2. class ArrayBag : Bag

    3. class ListBag : Bag

    4. class HeapBag : Bag

    5. is this a good hierarchy

      1. what's the relation

      2. what about related data types

    6. the problem is behavior and implementation are being mixed

  4. the bridge pattern - separating behavioral and implementation hierarchies

    1. have two hierarchies - one for behavior, the other for implementation

    2. the two top-level classes form the bridge between the two hierarchies

    3. why bother

      1. clarity - distinct concepts (behavior, implementation) are distinct

      2. reduced work - only one implementation needed

      3. flexibility - implementation choice, even dynamically


This page last modified on 25 January 2001.