Created
April 11, 2016 20:16
-
-
Save malalanayake/c88eda8c565cf2649d76018f1074eca7 to your computer and use it in GitHub Desktop.
Open-Close Principal - Good sample code
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
package sample.design.open.close.good; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 11, 2016 1:32:39 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class CircleNew implements ShapeNew { | |
public void draw() { | |
System.out.println("[PRINT:Circle]"); | |
} | |
} |
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
package sample.design.open.close.good; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 11, 2016 1:32:49 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class GraphicEditorNew { | |
public void drawShape(ShapeNew s) { | |
System.out.println("[INIT:Canvas]"); | |
s.draw(); | |
System.out.println("[RENDER:Canvas]"); | |
} | |
public static void main(String[] args) { | |
GraphicEditorNew ge = new GraphicEditorNew(); | |
// Print circle | |
CircleNew c = new CircleNew(); | |
ge.drawShape(c); | |
// Print Rectangle | |
RectangleNew rec = new RectangleNew(); | |
ge.drawShape(rec); | |
} | |
} |
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
package sample.design.open.close.good; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 11, 2016 1:31:29 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class RectangleNew implements ShapeNew { | |
public void draw() { | |
System.out.println("[PRINT:Rectangle]"); | |
} | |
} |
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
package sample.design.open.close.good; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 11, 2016 1:30:21 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public interface ShapeNew { | |
public void draw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment