Al's BrainDump

RSS

Navigation





Quick Search
»
Advanced Search »

PoweredBy

Table of Contents [Hide/Show]


         UML
      Decorator
      Proxy
      Bridge
      Composite
      Flyweight
      Adapter
      Façade
      Private class data pattern


UML

  • Dotted line: "is-a" (implements an interface)
  • Solid line with diamond at end: "has-a" (contains an instance of the other object)

Decorator

Adds additional properties\behaviours to an existing object - possibly after it has gone to prod. Original component is unaware of extra features.
  • Photo example: photo is the components, a border is a decorator:- the
  • Arbitrary number of extra decorations can be added by creating first decorator (which has component photo) and then creating as many new decorators as we like, passing in the last one we created as a component param to the constructor (as decorators and components all implement the iComponent interface).
  • The wrong old way to create arbitrary number of extra features on an object would be to inherit to a slightly modified version (1 extra feature), over and over again - ending up with a load of heavyweight objects. Mainly creating all these new classes would be ridiculous.

    Photo photo = new Photo();
    Tag foodTag = new Tag (photo, "Food",1);
    Tag colorTag = new Tag (foodTag, "Yellow",2);
  • You could keep creating new instances passing in the last created one (passing foodtag into colortage constructor) to get as many decorators as you like.
  • The genius is having the decorator class only have 1 extra feature and then creating new versions, building up the number of decorators required. (the iComponent interface must be implemented on component and decorators to allow this)

Proxy

Much as expected, the proxy class contains a reference to a "subject" class that the client would ordinarily have direct access to. Both subject and proxy implement iSubject interface so a client can use a proxy or subject if necessary.

Bridge

Redirects method calls to different implementations. .Net framework as an example - windows path variable is the bridge that points the the relevant version of the framework. All the different implementations support the iBridge interface and at runtime the client creates and uses an abstraction object with an implementation passed in as a param. The indirection means diff implementations can be used at runtime.

Composite

A composite is made up of components - so basically a list but it needs to implement iComponent (as does a component class) so a client uses iComponent to access both lists and single objects, using methods on both (delete, find etc). Used when you want to treat a component of a list in the same way as the list.

Flyweight

Helps reduce storage when state of an boject can be shared between multiple objects.

Adapter

Wrap an old library in an adapter to make whatever changes to parameters and return types are necessary so 1 client codebase can target different but functionaly similar libraries. The Adapter implements theITarget interface and routes calls from the Client through to the Adaptee (the thing that needs adapting).

Façade

A class offering a few high-level operations from several classes. These classes together comprise a complex system. The facade hides the complexity of the underlying components\classes. Amazon 1 click is a good example.

Private class data pattern

The private class data design pattern seeks to reduce exposure of attributes by limiting their visibility. It reduces the number of class attributes by encapsulating them in single Data object. It allows the class designer to remove write privilege of attributes that are intended to be set only during construction, even from methods of the target class. E.g. a circle class has private variables that cant be modified from outside the class but internal methods can modify them. This is undesirable. By creating a CircleData class with read only properties (but settable in the constructor) and this class is used by the circle class problem solved.



ScrewTurn Wiki version 3.0.5.600. Some of the icons created by FamFamFam.