Skip to main content

Posts

Showing posts from 2015

Abstract Factory pattern in java

        In Abstract Factory pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes. Each generated factory can give the objects as per the Factory pattern.  Abstract Factory  is Factory within factory. Its  come under creational Design Pattern in java Example: Step à 1.create interface Shape.java  Public interface Shape { Public void drawshape(); }   Color.java Public interface Color { Public void setcolor();  } Step à 2.implments shape Rectangle.java Public  Class  Rectangle implements  Shape { void drawshape() { System.out.println(“Rectangle drwn”); } } Circle.jva Public  Class  Circle implements  Shape { void drawshape() { System.out.println(“Circle  drwn”); } } Step.3 à implements color Interface Red.java Public class Red implements Color {  ...

Simple factory Design pattern

: If object creation code is spread in whole application, and if you need to change the process of object creation then you need to go in each and every place to make necessary changes. è creates objects without exposing the instantiation logic to the client è refers to the newly created object through a common interface Exapmle:      Step1.-->             Create interface:           Shape.java           Interface Shap{                   public void drowshape();                           } Step2.-->    Implment interface with Class        Create ...