Skip to content

Commit 37e2371

Browse files
committed
facade pattern demo
1 parent 8b00413 commit 37e2371

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

src/facade/Circle.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package facade;
2+
3+
public class Circle implements Shape{
4+
@Override
5+
public void draw() {
6+
System.out.println("Drawing a circle");
7+
8+
}
9+
}

src/facade/Main.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package facade;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
ShapeMaker shapeMaker = new ShapeMaker();
6+
7+
shapeMaker.drawCircle();
8+
shapeMaker.drawRectangle();
9+
shapeMaker.drawSquare();
10+
}
11+
}

src/facade/Rectangle.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package facade;
2+
3+
public class Rectangle implements Shape{
4+
@Override
5+
public void draw() {
6+
System.out.println("Drawing a rectangle");
7+
}
8+
}

src/facade/Shape.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package facade;
2+
3+
public interface Shape {
4+
void draw();
5+
}

src/facade/ShapeMaker.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package facade;
2+
3+
public class ShapeMaker {
4+
5+
private Shape circle;
6+
private Shape rectangle;
7+
private Shape square;
8+
9+
public ShapeMaker(){
10+
circle=new Circle();
11+
rectangle=new Rectangle();
12+
square=new Square();
13+
}
14+
15+
public void drawCircle() {
16+
circle.draw();
17+
}
18+
19+
public void drawRectangle() {
20+
rectangle.draw();
21+
}
22+
23+
public void drawSquare() {
24+
square.draw();
25+
}
26+
}

src/facade/Square.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package facade;
2+
3+
public class Square implements Shape{
4+
@Override
5+
public void draw() {
6+
System.out.println("Drawing a square");
7+
}
8+
}

0 commit comments

Comments
 (0)