Sunday, November 4, 2012

Iterator Design Pattern

The Iterator design pattern illustration, UML ...The Iterator design pattern illustration, UML diagram. (Photo credit: Wikipedia)
The iterator pattern is used to access objects that are stored in many different types of collection.
This is done by creating a common interface that all the different collection classes share. Then an iterator is provided to traverse the objects they contain.

Because all different Collection classes share a common interface they can be treated polymorphically and it eliminate duplicate code.


Below is the video tutorial for the Iterator pattern


State Design Pattern

English: UML Class Diagram of the State Design...English: UML Class Diagram of the State Design Pattern (Photo credit: Wikipedia)

Below is the video tutorial on State Design Pattern

Command Design Pattern

The UML diagram describing relations between o...The UML diagram describing relations between objects of the Command design pattern. (Photo credit: Wikipedia)
The UML diagram which describes the structure ...The UML diagram which describes the structure of the Command design pattern. (Photo credit: Wikipedia)


public interface Computer {
   void start();
   void shutdown();
}

public class Laptop implements Computer {
   public void start() {
       System.out.print("Laptop is started");
    }

    public void shutdown() {
       System.out.print("Laptop is shutdown");
    }

}

public interface Command {
   void execute();
   void undo();
}

public class StartLaptop implements Command {
   Computer theComputer;
   
    public StartLaptop (Computer newComputer ) {
        theComputer = newComputer;
    }

    public void execute() {
        theComputer.start();
    }
    
    public void undo() {
        theComputer.shutdown();
    }         
}

Below is the video tutorial about the Command pattern. 


Singleton Design Pattern Tutorial

Singleton Pattern is used to prevent instantiation of an object more than once.

Saturday, November 3, 2012

Abstract Factory Design Pattern

Factory Design Pattern

Factory design pattern is used to define the class of an object at runtime. It allows encapsulating object creation to keep all object creation code in one place. (separation of concerns)

You cannot instantiate an abstract class. It is just there to facilitate polymorphism.

Basic Principles of Object Oriented Technology