Created
April 26, 2017 10:29
-
-
Save dfucci/9ab9bc9a0905e766ee57138227643c2d to your computer and use it in GitHub Desktop.
Interface segregation principle
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
//Bad example | |
interface IWorker { | |
public void work(); | |
public void eat(); | |
} | |
class Worker implements IWorker{ | |
public void work() {// ....working} | |
public void eat() {// ...... eating in launch break} | |
} | |
class SuperWorker implements IWorker { | |
public void work() { //.... working much more} | |
public void eat() { //.... eating in launch break} | |
} | |
class Manager { | |
IWorker worker; | |
public void setWorker(IWorker w) {worker=w;} | |
public void manage() { | |
worker.work(); | |
} | |
} | |
//Good example | |
interface IWorkable { | |
public void work(); | |
} | |
interface IFeedable{ | |
public void eat(); | |
} | |
class Worker implements IWorkable, IFeedable{ | |
public void work() {// ....working} | |
public void eat() {//.... eating in launch break} | |
} | |
class Robot implements IWorkable{ | |
public void work() {// ....working} | |
} | |
class SuperWorker implements IWorkable, IFeedable{ | |
public void work() {//.... working much more} | |
public void eat() {//.... eating in launch break} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment