diff --git a/System Development/PatternFactory/.classpath b/System Development/PatternFactory/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/System Development/PatternFactory/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/System Development/PatternFactory/.project b/System Development/PatternFactory/.project new file mode 100644 index 0000000..06a31c6 --- /dev/null +++ b/System Development/PatternFactory/.project @@ -0,0 +1,17 @@ + + + PatternFactory + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/System Development/PatternFactory/src/Circle.java b/System Development/PatternFactory/src/Circle.java new file mode 100644 index 0000000..0e9400a --- /dev/null +++ b/System Development/PatternFactory/src/Circle.java @@ -0,0 +1,7 @@ +public class Circle implements Shape { + + @Override + public void draw() { + System.out.println("Inside Circle::draw() method."); + } +} \ No newline at end of file diff --git a/System Development/PatternFactory/src/PatternFactory.java b/System Development/PatternFactory/src/PatternFactory.java new file mode 100644 index 0000000..aa13560 --- /dev/null +++ b/System Development/PatternFactory/src/PatternFactory.java @@ -0,0 +1,24 @@ +public class PatternFactory { + + public static void main(String[] args) { + ShapeFactory shapeFactory = new ShapeFactory(); + + //get an object of Circle and call its draw method. + Shape shape1 = shapeFactory.getShape("CIRCLE"); + + //call draw method of Circle + shape1.draw(); + + //get an object of Rectangle and call its draw method. + Shape shape2 = shapeFactory.getShape("RECTANGLE"); + + //call draw method of Rectangle + shape2.draw(); + + //get an object of Square and call its draw method. + Shape shape3 = shapeFactory.getShape("SQUARE"); + + //call draw method of square + shape3.draw(); + } +} \ No newline at end of file diff --git a/System Development/PatternFactory/src/Rectangle.java b/System Development/PatternFactory/src/Rectangle.java new file mode 100644 index 0000000..1d2b442 --- /dev/null +++ b/System Development/PatternFactory/src/Rectangle.java @@ -0,0 +1,7 @@ +public class Rectangle implements Shape { + + @Override + public void draw() { + System.out.println("Inside Rectangle::draw() method."); + } +} \ No newline at end of file diff --git a/System Development/PatternFactory/src/Shape.java b/System Development/PatternFactory/src/Shape.java new file mode 100644 index 0000000..baae177 --- /dev/null +++ b/System Development/PatternFactory/src/Shape.java @@ -0,0 +1,4 @@ + +public interface Shape { + void draw(); +} diff --git a/System Development/PatternFactory/src/ShapeFactory.java b/System Development/PatternFactory/src/ShapeFactory.java new file mode 100644 index 0000000..4f5cdaa --- /dev/null +++ b/System Development/PatternFactory/src/ShapeFactory.java @@ -0,0 +1,20 @@ +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; + } +} \ No newline at end of file diff --git a/System Development/PatternFactory/src/Square.java b/System Development/PatternFactory/src/Square.java new file mode 100644 index 0000000..33e1b21 --- /dev/null +++ b/System Development/PatternFactory/src/Square.java @@ -0,0 +1,7 @@ +public class Square implements Shape { + + @Override + public void draw() { + System.out.println("Inside Square::draw() method."); + } +} \ No newline at end of file