c010depunkk’s bl0g

the hangout of a web designer

Archive for the ‘Design Patterns’ Category

Design Patterns - Bridge

Design Patterns - Bridge PDF download

Decouple an abstraction from its implementation so that the two can vary independently.

This is one of my favorite Design Patterns and I've used it quite often when coding with GUI's. It allows you to completely seperate your GUI and your implementations of reactions to user input. For example, instead of calling a Windows MessageBox directly:

C#:
  1. MessageBox.Show("bla","blub");

You create a "Bridge" class with a public "showMessageBox" function. You then have various classes for Windows, Mac, etc. which implement a message box for that specific OS. The Bridge class then serves as a bridge between your implementation and the specific implementations for the various OS's.

Design Patterns - Abstract Factory

Design Patterns - Abstract Factory PDF download

The Abstract Factory Design Pattern "provide[s] an interface for creating families of related or dependent objects without specifying their concrete classes." Sounds complicated, but is easier to understand with an example:

The controls on a skinnable program can be either red or black. The Abstract Factory provides the right controls to the rest of the code like so:

C++:
  1. AbstractFactory controlSupplier = new AbstractFactory();
  2.  
  3. Button b = controlSupplier.getButton();

This means that the other classes in the code don't have to worry about the skinning of the controls, all they have to do is ask the Abstract Factory instance to provide the right kind of control and they get a fully skinned and customized control.

Design Patterns - Decorator

Design Patterns - Decorator PDF download

The Decorator Design Pattern adds functionality or features to an object dynamically. It's interface conforms to that of the component it is decorating which allows an unlimited, transparent nesting.

Design Patterns - Composite

Design Patterns - Composite PDF download

This is the first of the Design Patterns.

The intent of the Composite Design Pattern is to let clients treat individual objects and compositions of objects uniformly in a tree-hierarchy. This is accomplished through an abstract class that defines an identical interface for both primitives and their containers. The client then does not need to know if the object it is currently accessing is a single primitive or a collection of same. This allows objects to be nested almost endlessly....

Design Patterns - How They Solve Problems

Design Patterns - How They Solve Problems PDF download

Strict modeling of the real world leads to a system that reflects today’s realities but not necessarily tomorrow’s.

One very important aspect of design patterns is the interface. An object's interface everything that is "visible to the outside" (name, variables, functions, parameters, return values).

Objects are only known through their interfaces.

Two objects having completely different implementations can have identical interfaces.

These two statements are key to understanding Design Patterns.

Another key statement is "design for change!"