Last active
March 5, 2020 11:20
-
-
Save pfieffer/4c3177afdd73d93918d94a2d35313153 to your computer and use it in GitHub Desktop.
FacadePatternDemo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Circle implements Shape { | |
| @Override | |
| public void draw() { | |
| System.out.println("Circle::draw()"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FacadePatternDemo { | |
| public static void main(String[] args) { | |
| ShapeMaker shapeMaker = new ShapeMaker(); | |
| shapeMaker.drawCircle(); | |
| shapeMaker.drawRectangle(); | |
| shapeMaker.drawSquare(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Rectangle implements Shape { | |
| @Override | |
| public void draw() { | |
| System.out.println("Rectangle::draw()"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface Shape { | |
| void draw(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ShapeMaker { | |
| private Shape circle; | |
| private Shape rectangle; | |
| private Shape square; | |
| public ShapeMaker() { | |
| circle = new Circle(); | |
| rectangle = new Rectangle(); | |
| square = new Square(); | |
| } | |
| public void drawCircle(){ | |
| circle.draw(); | |
| } | |
| public void drawRectangle(){ | |
| rectangle.draw(); | |
| } | |
| public void drawSquare(){ | |
| square.draw(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Square implements Shape { | |
| @Override | |
| public void draw() { | |
| System.out.println("Square::draw()"); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Circle,RectangleandSquareare all implementations ofShape.The
ShapeMakeris the Facade to all the Shapes.FacadePatternDemoclass shows how the Facade can be used to draw different shapes.Read more? : https://www.tutorialspoint.com/design_pattern/facade_pattern.htm