Design Patterns

Wednesday, May 17, 2006

Lecture 7 :14 March 2006

Structural Patterns

Structural patterns deal with the composition of larger structures among objects and classes. Utilisation of inheritance is a common feature used in structural class patterns in the composition of intrefaces and in implementation.
There are 7 structural patterns namely; proxy, decorator, composite, flyweight, Facade, Adapter and bridge.

Adapter
This pattern brings together two different interfaces together due to incompatibility, and its put in an interface the client expects.

Take an example of a household adapter, it will accept a two pin plug so that it goes into the three pin socket in the wall. The adapter facilitates for the connectivity of these two diffeent interfaces which are not incompatile to communicate/work together.
The adapter will prove useful when you want to make a class that don't relate/match to the one required(incompatibility)
One of the consequences that may arise is that it may take over the attributes of the adaptee as it will be a subclass of the adapter.
The adapter can be likened to the bridge pattern.

Decorator
Its a pattern that gives extra reaponsibilities to an object dynamically. Instead of always using subclassing for extension of fuctions, the decorator can be used as an alternative to subclassing.
The decorator is suitable for use in situations where you do not want to affect the other objects, by adding responsibilities to the one object.

Bridge
This pattern separates the abstraction from its implementation in order for the two to vary independently.
Its mostly used in situations where you do need permanent bonding of the implementation and abstraction. The bridge pattern encourange the improvement of extensibility as it can be done independently. Lastly the process in the abstraction and implementation are hidden from the client.

Composite
It composes objects in a tree structure and presents them as part-whole hierarchies, which composes of the leaf, the composite and the component. All the objects are treated uniformily in the composite. The composite also supports easy extensibility.

Flyweight - effective management of huge numbers of objects through sharing

Proxy - its an object that is acting on behalf of another object to control access

Facade - provides a single object representing the whole system.

References:

Gamma, E., Helm, R., Johnson R., & Vlissides, J. (1994) Design Patterns: elements of reusable software, Addison Wesley, ("Gang of Four Book (GoF)") pg 395






1 Comments:

  • At 8:30 AM, Blogger Lolo said…

    Interesting write up l needed a simpe but deatiled explanation of structural patterns

     

Post a Comment

<< Home