Created
January 18, 2018 10:39
-
-
Save YuanLiou/81a15ca156f37c147ffd48f98f706d55 to your computer and use it in GitHub Desktop.
Liskov Substitution Principle
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
public class somebody { | |
public static void main(String[] argv) { | |
Store store = new Store(); | |
List<Cellphone> cellphones = store.getCellphones(); | |
for (int i = 0; i < cellphones; i++) { | |
cellphones[i].power(false); | |
} | |
iPhone iphoneX = new iPhone(); | |
cellphones.add(iphoneX); | |
} | |
public void callMom(Cellphone cellphone) { | |
cellphone.call(mom) | |
} | |
} | |
// Cellphone | |
public interface Cellphone { | |
void call(People people); | |
void textMessage(String text); | |
void power(boolean powerOn); | |
} | |
public abstract class Cellphone {} | |
// Entity | |
public class Nokia3310 implement Cellphone { | |
public void strong() { /* WOWOWOWOWOW */ } | |
@Override | |
public void call(People people) { /*do something */ } | |
@Override | |
public void textMessage(String text) { /* do something */ } | |
@Override | |
public void power(boolean powerOn) { /* do something */ } | |
} | |
public class iPhone implement Cellphone { | |
public void surfingInternet() { /* I's so cool!!!! */ } | |
public void installApp() { /* I's so cool!!!!! Again */ } | |
@Override | |
public void call(People people) { /*do something */ } | |
@Override | |
public void textMessage(String text) { /* do something */ } | |
@Override | |
public void power(boolean powerOn) { /* do something */ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment