Tuesday, 20 February 2007

20 Feb 2007 Design Patterns, Zero to 60 in 3 seconds (i mean 3 weeks)

20 Feb 2007

In this third lesson today we learned what Design Patterns are, people behind its origin and the way they preserve it.
In a nut shell in software engineering Design Patterns are solutions to the design problems in a context. Firstly found in 1987 by Christopher Alexander but gained popularity after the book Design Patterns: Elements of Reusable Object-Oriented Software by Gamma et al in 1994. They documented each pattern in way that it will contain enough information about the problem, the context and salutations with sample code.


Todays task was to choose one of the GoF design patterns out of 23 and try criticising all its elements.
I think criticising a work done by professional with experiences over 40 years is very difficult especially by the person who is new to patterns. but I suppose it will help me understand the pattern I have chosen better, how the elements are preserved and what do they contain. Anyhow, I have chosen Facade pattern. There is no specific reason why I choose it; I guess I just liked the name.

FACADE
Intent
As the name implies we talk about the intention behind creating this pattern. Façade is very simple; it basically gives one (high level) interface to the number of interfaces in the subsystem. Thus it makes easier to oversee underlying interfaces in the subsystem.

Motivation
Adding an additional interface or system over subsystem helps reduce complexity, communication and dependencies between subsystems and that why Façade is introduced to provide unified facility.
Applicability
In other words places where it is suitable to apply Facade
  • A simple interface is required to replace a complex subsystem
  • Numerous dependencies exist between the implementation (abstract) class and client
  • Also for layering the subsystem

Structure
Every pattern will have structure of its own. A diagram is normally used to describe the structure, which makes understanding very easier.
The structure that Façade adds to the system is more understandable using diagram, but for now Use this example to understand. As we go the Mc Donald’s Drive Thru Only and order something, one person goes and brings fries, burger and drinks to the window. There aren’t different windows for fries, drinks or burgers. So that only ONE Window is acting as a Façade.


Participants
Participants are the bodies making the pattern function. Thinking of the food again, as we have ingredients part for every dish in cookbook, we also have participant elements for every pattern in GOF book.

Facade (Compiler)
Subsystems classes (Scanner, Parser, ProgramNode, etc.)

Collaborations
In collaboration we talk about how and what mingles with the pattern, which is Façade here.
Client uses Façade as a middle man to communicate with the subsystem objects and thus client do not have to access subsystems objects directly.

Consequences
Usage of every pattern will bring some end result, its not necessary that consequences will always be beneficiary, it may have some shortcomings too. Good descriptions will have all, the Benefits, Shortcomings of the pattern and Advice on what to do about the shortcomings. Some benefits of using Façade is that It makes subsystem easier to use and reduced complex dependencies between objects. However it it gives an option between ease of use or generality because it does not prevent subsystem classes useage.


Implementation
Here we know that the method of implementing the pattern will be advised but useful tricks of it be will be helpful too, and not to forget the things to avoid during implementation.
In Façade when implementing:
-The pairing between clients and the subsystem can be reduced even further by making Facade an abstract class with concrete subclasses for different implementations of a subsystem.
- Making subsystem classes private would be useful,

Sample Code
Here we put the sample code to show how lay pattern; Façade on the complier

Known Uses
For beginners like me, this element is very helpful t understand in greater dept by looking at the real examples of the system where it is used or can be used.

Related Patterns
A brief details about which patterns are similar or can be linked to Façade.
Mediator and abstract factory pattern can be ralted and can be used alongside.

I hope the reader will get some knowledge about Façade and the way patterns are documented. And hope you enjoy reading it as much as I enjoyed in writing it.


Source: http://www.javaprogrammingworld.com/java-design-patterns.doc

3 comments:

John Ssebaale said...

Hi, thanks for the criticism of the pattern. you did it well giving both the good side and the bad side of the cataloguing technique. I think its ok.

Well done
Cheers

Anonymous said...

Sir!

Thanks indeed for the information.

It’s unfortunate to mention but even after I’ve gone through your criticism on FACADE Pattern several times in order to understand what is it all about I have literally lost the interest and leaving it as it is without any understanding @ all.

Much obliged.

Asmat Ali said...

I don’t know much about patterns but after reading it I gained lot of knowledge.