Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class AbstractFactoryPatternDemo
  2. {
  3.    public static void main(String[] args) {
  4.  
  5.       //get shape factory
  6.       AbstractFactory shapeFactory = FactoryProducer.getFactory("SHAPE");
  7.  
  8.       //get an object of Shape Circle
  9.       Shape shape1 = shapeFactory.getShape("CIRCLE");
  10.  
  11.       //call draw method of Shape Circle
  12.       shape1.draw();
  13.  
  14.       //get an object of Shape Rectangle
  15.       Shape shape2 = shapeFactory.getShape("RECTANGLE");
  16.  
  17.       //call draw method of Shape Rectangle
  18.       shape2.draw();
  19.      
  20.       //get an object of Shape Square
  21.       Shape shape3 = shapeFactory.getShape("SQUARE");
  22.  
  23.       //call draw method of Shape Square
  24.       shape3.draw();
  25.  
  26.       //get color factory
  27.       AbstractFactory colorFactory = FactoryProducer.getFactory("COLOR");
  28.  
  29.       //get an object of Color Red
  30.       Color color1 = colorFactory.getColor("RED");
  31.  
  32.       //call fill method of Red
  33.       color1.fill();
  34.  
  35.       //get an object of Color Green
  36.       Color color2 = colorFactory.getColor("Green");
  37.  
  38.       //call fill method of Green
  39.       color2.fill();
  40.  
  41.       //get an object of Color Blue
  42.       Color color3 = colorFactory.getColor("BLUE");
  43.  
  44.       //call fill method of Color Blue
  45.       color3.fill();
  46.    }
  47. }