Created
April 12, 2016 18:39
-
-
Save malalanayake/a8eb8f325daaca022e1bf51732923279 to your computer and use it in GitHub Desktop.
Interface Segregation Principal - Sample code
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
package sample.design.Interface.segregation.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 1:25:34 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class Human implements Worker { | |
public void startWork() { | |
System.out.println("[START:Working Human]"); | |
} | |
public void stopWork() { | |
System.out.println("[STOP:Working Human]"); | |
} | |
public void eat() { | |
System.out.println("[EAT:Lunch Human]"); | |
} | |
} |
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
package sample.design.Interface.segregation.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 1:27:46 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public class Robot implements Worker { | |
public void startWork() { | |
System.out.println("[START:Working Robot]"); | |
} | |
public void stopWork() { | |
System.out.println("[STOP:Working Robot]"); | |
} | |
/** | |
* The interface force to implement the method which is not needed. | |
*/ | |
public void eat() { | |
System.out.println("[NOT APPLICABLE]"); | |
} | |
} |
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
package sample.design.Interface.segregation.bad; | |
/** | |
* | |
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991 | |
* | |
* @author dmalalan | |
* @created Apr 12, 2016 1:23:31 PM | |
* | |
* @blog https://malalanayake.wordpress.com/ | |
*/ | |
public interface Worker { | |
public void startWork(); | |
public void stopWork(); | |
public void eat(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment