Design Pattern - Factory Pattern

PHOTO EMBED

Sun May 08 2022 05:32:19 GMT+0000 (Coordinated Universal Time)

Saved by @suhasjoshi #designpattern #factorypattern

public class ShapeFactory {
	
   //use getShape method to get object of type shape 
   public Shape getShape(String shapeType){
      if(shapeType == null){
         return null;
      }		
      if(shapeType.equalsIgnoreCase("CIRCLE")){
         return new Circle();
         
      } else if(shapeType.equalsIgnoreCase("RECTANGLE")){
         return new Rectangle();
         
      } else if(shapeType.equalsIgnoreCase("SQUARE")){
         return new Square();
      }
      
      return null;
   }
}
content_copyCOPY

Sample code for Factory design Pattern

https://www.tutorialspoint.com/design_pattern/factory_pattern.htm