Design Patterns

Types of Adapters - Adapter Pattern

Lets say our application uses a component A and now we want to replace A with a component from 3rd party , say it as B. Since the component B is not in our control which means we dont have control on its interface as well. But the problem here is that our client code is already using interface A and we dont want it to change. How can existing and unrelated classes work in an application that expects classes with a different and incompatible interface? This is the problem we will be going to res

posted @ Monday, June 16, 2008 3:56 PM | Feedback (0)

Data Transfer Objects (DTO)

Today I will give you an overview of Data Transfer Objects (DTO). We will discuss what are they and how are they used and where.

DTO as defined by Martin is "An object that carries data between processes in order to reduce the number of method calls"

Lets read more on this .....

posted @ Friday, June 06, 2008 12:30 PM | Feedback (0)

Chain of Responsibility Pattern

COR Objective To provide the appropriate handler present in the chain of handlers which can handle the incoming request. Advantages Loose coupling. This is based on "Data-Driven" concept. Distribution of responsibilities

posted @ Friday, May 16, 2008 6:52 PM | Feedback (0)

Iterator Pattern

An aggregate object should give a way to access its elements without exposing its internal structure. There may be different ways to iterate through different elements. It is not advisable to flood your aggregate object with so many iterating mechanisms.

"Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation" .... Read more

posted @ Tuesday, May 06, 2008 10:53 AM | Feedback (0)

Memento Pattern

Sometimes it's necessary to record the internal state of an object. This is required when implementing checkpoints and undo mechanisms that let users back out of tentative operations or recover from errors. You must save state information somewhere so that you can restore objects to their previous states.

Memento lets u do this , read more for examples

posted @ Monday, May 05, 2008 5:04 PM | Feedback (0)

Factory Method Pattern

This pattern is also called as Virtual Constructor

Frameworks use abstract classes to define and maintain relationships between objects. A framework is often responsible for creating these objects as well.

Since Framework in not aware of applications for which it will be used, hence it is not aware of the sub classes of abstract classes it provides and therefore it delegates the responsibility of creating the instances of application specific class to the sub classes.....

posted @ Monday, May 05, 2008 1:03 PM | Feedback (0)

Observer Pattern

Observer Pattern define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Dependent Objects are termed as Observers. New Observers can easily be hooked in an existing list of Observers.

This article explains Observer pattern with example in Java. Read more for details

posted @ Friday, May 02, 2008 7:35 PM | Feedback (0)

Singleton Design Pattern

Singleton pattern is one of the most used design patterns in any system. The pattern states that

"Ensure a class only has one instance, and provide a global point of access to it."

Although it is simple to implement this pattern, I have explained the pattern with a real world example and diagrams. Read more for details

posted @ Wednesday, April 30, 2008 4:43 PM | Feedback (0)

Composite Design Pattern

In this article I will discuss about one of the Structural pattern in GoF series which is composite pattern.

Composite pattern defines class hierarchies consisting of primitive objects and composite objects. Primitive objects can be composed into more complex objects, which in turn can be composed, and so on recursively.

It makes the client simple. Clients can treat composite structures and individual objects uniformly. Read more for examples and diagrams

posted @ Wednesday, April 30, 2008 1:16 PM | Feedback (0)

Decorator Pattern

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Sometimes we want to add responsibilities to individual objects, not to an entire class.One way to add responsibilities is with inheritance. Inheritence will cause all the objects of that derived class to change.

A more flexible approach is to enclose the component in another object that adds the border. The enclosing object is c

posted @ Monday, April 21, 2008 2:24 PM | Feedback (2)

Template Pattern

This article is part of our series of design patterns. The definition of Template pattern states that

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

The article demonstrates the pattern with UML diagrams and a C# code example

posted @ Monday, April 21, 2008 11:25 AM | Feedback (0)

MVC Pattern

MVC stands for Model View Controller Pattern This pattern is extensively used while architecting an enterprise J2EE applications.

posted @ Friday, April 18, 2008 7:21 PM | Feedback (0)

Strategy Pattern

When to use Strategy Pattern When we have multiple implementations(algorithms) When we follow composition relationship(has-a) in place of the inheritance relationship(is-a relationship) When we have a variety of behaviors but these are not applicable to all the objects

posted @ Tuesday, April 15, 2008 8:04 PM | Feedback (0)