Skip to content

Instantly share code, notes, and snippets.

@malalanayake
Created April 12, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malalanayake/a8eb8f325daaca022e1bf51732923279 to your computer and use it in GitHub Desktop.
Save malalanayake/a8eb8f325daaca022e1bf51732923279 to your computer and use it in GitHub Desktop.
Interface Segregation Principal - Sample code
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]");
}
}
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]");
}
}
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