Class 8 DP Structural
Class 8 DP Structural
Based on slides of: Mira Balaban Department of Computer Science Ben-Gurion university
F. Tip. IBM T J Watson Research Center.
Structural Patterns
concerned with how classes and objects are composed to form
larger structures
structural class patterns: use inheritance to compose interfaces or
implementations.
structural object patterns: describe ways to compose objects to realize new
functionality.
structural patterns:
Adapter Façade
Composite Bridge
Proxy Decorator
Flyweight
interface Stack {
public void push(Object o);
public Object pop();
public int nrElements();
}
Problems:
a combinatorial explosion in number of classes
difficulties in sharing of implementations
exposure of platform dependencies to clients
1 2 3 2
tail
3
}
}
LinkedListBasedStack ArrayBasedStack
Stack With Swapping
…
+swap
leaf
Composite
leaf
Composite leaf
Composite leaf
Composite
leaf leaf
...
// at some point later - maybe text size becomes larger than the VisualComponent
thus the scrolling behavior must be added
// decorate the exiting VisualComponent
vComponent = new ScrollDecorator (vComponent );
// now VisualComponent object has additional behavior / state
vComponent .draw();
}
}
Time/space tradeoffs.