I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Showing posts with label Design Patterns. Show all posts
Showing posts with label Design Patterns. Show all posts

Friday, 11 January 2008

Behavioral Pattern

Gamma et al have also described a number of behavioral patterns:
  • Chain of responsability (a request goes through an ordered chain of potential Workers, the appropriate worker determines that he has to treat the request, in that way the requester does not need to know any thing about the receiver of the request)
  • Command (a request is wrapped in to an object in order to allow the parametrisation, the queueing, logging or cancellation of the request)
  • Interpreter ()
  • Iterator (a mean of accessing sequentially the elements of a aggregate object without revealing its internal structure)
  • Mediator (an object which encapsulate the way different object interact with each others)
  • Memento (method to capture and externalise the structure of an object to restore it later)
  • Observer (an object offers the possibility of registering a number of observers which are notified as soon as some state is reached)
  • State (the behavior of an object is dependant on the internal state of the object )
  • Strategy ( define a number of interchangeable algorithms which can be used for a variety of clients and situations)
  • Template Method ( defines a super class which provides a skeleton of the different steps which have to be performed in an algorithm, the subclasses of this superclass implement specifically these parts)
  • Visitor (define operation which have to be performed on some objects of a structure and store the code for this operation in a separate object)

Structural Patterns

We now turn to the Structural patterns proposed by Gamma et al.
  • Adapter (a class or interface created in order to adapt an object for another implementation)
  • Bridge (the abstraction is separated from the implementation of a classso that they can evolve independantly)
  • Composite (structures are organised in tree structures in order to model part-whole relationships but still offer a somewhat similar mean of interaction)
  • Decorator (supplementary functionalities are attached to an object dynamically)
  • Facade (provide a higher level interface thus simplifying its use)
  • Flyweight (in order to support a large amount of fine-grained objects resources are shared)
  • Proxy (an object serving as surrogate for another object in order to simplify the control of the original object)

Creational Patterns

The Gamma book cites five creational patterns:
  • Abstract factory (This provides an abstract way to ensure a common method of creation of objects, through an interface that all the factories have to implement)
  • Builder (Creates an object which is specialisedin the construction of a complex from its representation)
  • Factory Method (define an abstract method for creating object but let subclasses decide of the details of the implementation and instantiation)
  • Prototype (objects are first created using a prototype instance which is copied in order to create new instances of this type)
  • Singleton (a class may have only one instance, and some method to get this instance is clearly defined and unambiguous)

Design Patterns

Since I have read the Gamma et al. book on design patterns, I tend to see most of the programming techniques as a set of design patterns which one combines with one another. There are many useful design patterns and the categorisation given in the Gamma book is at least useful to get an overview of these relevant design patterns:
  • creational patterns
  • structural patterns
  • behavioral patterns
The description of each of the design patterns follows a simple structure:
  • Intent (succint description of the intent of the design pattern)
  • Other Names (other names which have been given to this pattern)
  • Motivation (gives a description of the type of problem for which this pattern can be used)
  • Applicability (gives a summary of the main guidelines when to use the pattern)
  • Structure (gives a UML description of the overall structure of the pattern)
  • Participants ( a description of the main elements or classes used in the structure)
  • Collaboration (describes how the elements are used in cooperation with the others)
  • Consequences (the main consequences of the use of the pattern)
  • Implementation (a description of how to implement the pattern in a sensible way)
  • Sample Code ( some sample code of the use and of the implementation)
  • Known Uses (some example where this pattern has been used effectively)
  • Related Patterns ( explains the relation this pattern has to other patterns)