RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Wednesday, August 26, 2009

Few Points Related To Design Patterns

Hi friends,

Its been sometime since we shared some information regarding the concepts(For those who missed out, We had been doing Few Java Quizzes! Check It out Here

Today I would like to present a general hint which would be helpful for people who want to take seminars in Design Patterns.

Without wasting further time, Here We Go!

Before Design Pattern:

Interface – Car and TV remote
Abstract Class – I10
Is a - has a
Aggregation - If the History-Class object is destroyed, the Student objects may continue to exist.
History-Class << --->Student
(Weak relationship)
Composition - If the House object is destroyed, the Room objects will also be destroyed.
(Strong relationship) House << --- > Room

Architecture – Skeletal view
Framework – Implementation

Organizing the patterns:

Creational – Involve object instantiation and all provide a way to decouple a client from the objects
it needs to instantiate.
Behavioral – It is concerned with how classes and objects interact and distribute responsibility.
Structural – It lets you compose classes or objects into larger structures.

GOF – Gang of four (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides) author’s of the book

There are 250 patterns in oo world where 23 are familiar and well known patterns.


“Ensure a class has one instance and provide a global point of access to it”
public class single {
private static single s;
private single() { };

public static synchronized single getInstance()
s = new single();
return s;
//other methods continue here

Factory Method:

Based on your data, we are going to instaniate an object of a classes
Car<- Buick, Chevrolet, Ford, Pontiac and Saturn
public class OrderCars
public Car orderCar(String model)
Car car;
car = new Buick(model);
else if(model.equals("Corvette"))
car = new Chevrolet(model);
else if(model.equals("Fusion"))
car = new Ford(model);
else if(model.equals("GTO"))
car = new Pontiac(model);
else if(model.equals("Vue"))
car = new Saturn(model);
When a class does not know which class of objects it must create.

Abstract Factory:

Its a super set of Factory method pattern

public class ComputerType {
private Computer comp;
public static void main(String[] args) {
ComputerType type = new ComputerType();
Computer computer = type.getComputer("Server");
System.out.println("Monitor: "+computer.getMonitor().getSpecification());
System.out.println("RAM: "+computer.getRAM().getSpecification());
System.out.println("Processor: "+computer.getProcessor().getSpecification());
* Returns a computer for a type
* @param computerType String, PC / Workstation / Server
* @return Computer
public Computer getComputer(String computerType) { if (computerType.equals("PC"))
comp = new PC();
else if(computerType.equals("Workstation"))
comp = new Workstation();
else if(computerType.equals("Server"))
comp = new Server();
return comp;
} }// End of class

Builder and Prototype


Strategy - It desines a set of algorithm and make them interchangable based on client request (refer ppt )
Observer - Refer ppt It defines a one-to-many dependency between objects so that when one object change state,
all of its dependents are notified and updated automatically (refer ppt)
Chain of Responsibility , Command , Interpreter , Iterator , Mediator, Memento


Adapter: It converts the interface of a class into another interface the client expects. Adapter lets
classes work together that couldn’t otherwise because of incompatible interfaces (refer ppt )
Façade: This is nothing but the outlook of an object.It hides the complexity of our implementation
(refer ppt ).

Bridge ,Composite, Decorator, Façade, Flyweight and Proxy

This Information As Said Earlier is only a general hint which would be helpful for people who want to take seminars.
Hope It was useful to you, Please Post your comments!

No comments: