Skip to main content

Posts

Showing posts from June, 2015

Design Patterns/Algorithm/OOP Design Principle

Design Pattern Question : What is Factory Design Pattern in Java? Factory pattern is one of most used design pattern in Java. This type of design pattern comes under creational pattern. In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface. Implementation We're going to create a Shape interface and concrete classes implementing the Shape interface. A factory class ShapeFactory is defined as a next step. FactoryPatternDemo, our demo class will use ShapeFactory to get a Shape object. It will pass information (CIRCLE / RECTANGLE / SQUARE) to ShapeFactory to get the type of object it needs. Step 1 Create an interface. Shape.java public interface Shape {    void draw(); } Step 2 Create concrete classes implementing the same interface. Rectangle.java public class Rectangle implements Shape {    @Override    public void draw() {       System.out.println("Inside