Lecture Notes for Advanced Programming II
25 January 2001 - The Bridge Object Pattern
- consider the bag data structure - like a set but with multiple elements
- operations - add, get, member, count, clear
- possible implementations
- array - simple and fast, but fixed
- linked list - not so simple or fast, but dynamic
- hash table - hard, but fast (usually) and dynamic
- from this get the usual inheritance hierarchy
- class Bag
- class ArrayBag : Bag
- class ListBag : Bag
- class HeapBag : Bag
- is this a good hierarchy
- what's the relation
- what about related data types
- the problem is behavior and implementation are being mixed
- the bridge pattern - separating behavioral and implementation hierarchies
- have two hierarchies - one for behavior, the other for implementation
- the two top-level classes form the bridge between the two hierarchies
- why bother
- clarity - distinct concepts (behavior, implementation) are distinct
- reduced work - only one implementation needed
- flexibility - implementation choice, even dynamically
This page last modified on 25 January 2001.