Tuesday, 13 March 2007

Explanation and Criticism of GoF's Patterns. Exploring patterns in C++ !!


Today we have looked deep in to design patterns. We have been introduced to famous GOF design patterns.

In a nutshell we have discussed about

Design patter in general
Importance and uses of design patterns
Types of design patterns
The famous GOF pattern and its preserving techniques


In my blog, I will be looking at two major tasks as we have been asked to by Dr. SRI.

1. Explain GoF (Gang of four) patterns in general and criticism of GoF pattern preserving technique.

2. Identify a design pattern example other than the ones listed in handouts

Let’s look at the GoF design pattern in general.

The GoF design patterns are in the middle of these levels of abstraction

“A design pattern names, abstracts, and identifies key aspects of a common design structure that makes it useful for creating a reusable object-oriented design.” [1]

The GoF design patterns are “descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.”

Riehle and Zullighoven in “Understanding and Using Patterns in Software Development” mentions three types of software patterns

Conceptual Pattern

Pattern whose form is described by means of terms and concepts from the application domain

Design Pattern


Pattern whose form is described by means of software design constructs, such as objects, classes, inheritance and aggregation

Programming Pattern (Programming Idiom)

Pattern whose form is described by means of programming language constructs

According to task no 1 I have gone through Abstract factory and understood the concept of preserving technique. I have identified all the elements below and included criticism of GoF pattern at the end.


Pattern Name and Classification


A good, concise name for the pattern and the pattern's type

Intent
Short statement about what the pattern does

Also Known As
Other names for the pattern

Motivation
A scenario that illustrates where the pattern would be useful

Applicability
Situations where the pattern can be used

Structure
A graphical representation of the pattern

Participants
The classes and objects participating in the pattern

Collaborations
How to do the participants interact to carry out their

Consequences
What are the pros and cons of using the pattern?

Implementation
Hints and techniques for implementing the pattern

Criticism
There are criticisms about the whole concept of pattern. There are both pessimistic and optimistic view on GoF’s preserving techniques some of the issues I have noticed are listed below which are collected from Salingaros’ paper

· Criticism of GOF Design Patterns catalogue-feel and lack of connective rules applies equally well to Alexander's architecture patterns books.


· Design is tremendously hard work, and patterns do not provide an algorithm or make the hard work go away.

· Alexander sorts his patterns in order of decreasing scale, since decisions on the largest scale have to be made first; does GOF do this?

Identify a design pattern example other than the ones listed in handouts

For task number two I have gone through lots of research papers and came across lots of interesting patterns. One of the pattern which I would like know further is a patterns which have been developed for C++ program. According to the paper the abstract of this pattern is as follows

“Sequential control flow forms the backbone of any procedural program. Just as common function, data, and structure in a C++ program can be factored out using functions, classes, and templates, common control flow schemas can also be named and abstracted. One such recurring schema, or programming cliché, is the embracing or bracketing of a sequence by a pair of actions, such as resource acquisition and release operations executed around the actual resource usage code.” [2]

Name
EXECUTE-AROUND OBJECT

Problem
How do you abstract the execution of a pair of actions that surround a sequence of statements, or a single action that follows a sequence?

Solution
Provide a helper class for declaring a local object before the sequence. Its constructor is provided with any arguments necessary to perform the before action, and any that must be remembered for the destructor to perform the after action.

Name
EXECUTE-AROUND PROXY

Problem
How can you apply EXECUTE-AROUND OBJECT conveniently for individual calls on an object?

Solution
Provide a PROXY that forwards function calls to the target object, with each call wrapped by an EXECUTE-AROUNDOBJECT.



Name
EXECUTE-AROUND POINTER

Problem

How do you define an EXECUTE-AROUND PROXY when the actions performed on a target object are the same for all functions?

Solution
Define a SMART POINTER whose operator-> returns a temporary SMART POINTER. The temporary's operator-> performs the before action and its destructor performs the after action.

Name
EXECUTE-AROUND FUNCTION

Problem

How do you safely group and execute a sequence of statements that must be enclosed by a pair of actions, or followed by a single action?

Solution
Provide a function or object that holds the sequence of statements and pass it to another function for execution. The called function also executes the before and after actions as necessary.

References:




[1]Design Patterns: Elements of Reusable Object-Oriented Software By Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides




[2]http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/ExecutingAroundSequences.pdf

3 comments:

Iqbal said...

It is a nice piece of work.The criticism of the preserving technique is an interseting one where you have talked about the Alexander's and GOF's patterns.
Keep up your good work!!!

Anonymous said...

hi immy, your pattern example is great. I check the link and it is really helpful related to coding examples also. Anyway you know if you have selected GoF approach above in task 1 then use the same approach e.g. Intent, Motivation, Applicability, Structure, etc. for your example in task 2. I am still working on to find a good example of patterns other than listed in handouts.

Anonymous said...

Hay its a good link for me to get some help in coding