- How can I use circle, square, triangle and any shape that comes in future to draw?
- How can I draw pictures that are composed from triangles, squares, or circles or any future shape?
- I want to make sure that always circles are drawn first, squares are second and triangles are third?
Created
April 17, 2020 10:54
-
-
Save DhavalDalal/54a9e0961011c7afabe0168d5ef82137 to your computer and use it in GitHub Desktop.
Refactoring - ocp
This file contains 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
class Canvas { | |
public void draw(Circle c) { | |
System.out.println("Canvas drawing a circle."); | |
} | |
public void draw(Square s) { | |
System.out.println("Canvas drawing a square."); | |
} | |
public void draw(Triangle t) { | |
System.out.println("Canvas drawing a triangle."); | |
} | |
public void draw(List<?> shapes) { | |
// loop through each shape and draw | |
System.out.println("Canvas drawing a picture here using the square, circle etc..."); | |
} | |
} |
This file contains 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
class Circle { | |
public void draw() { | |
System.out.println("Drawing Circle..."); | |
} | |
} |
This file contains 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
class Square { | |
public void draw() { | |
System.out.println("Drawing square...."); | |
} | |
} |
This file contains 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
class Triangle { | |
public void draw() { | |
System.out.println("Drawing triangle...."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment