Created
June 17, 2020 21:19
-
-
Save luissilvazup/43c3e70d8eaf3b1cffccb20e3acfa011 to your computer and use it in GitHub Desktop.
LSP Problem
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
public class L_LiskovSubstituitionProblem { | |
@Getter | |
@Setter | |
private static class BasicAccount { | |
protected double balance = 0; | |
public void yield() { | |
this.balance += (this.balance * 0.15); | |
} | |
} | |
private static class SalaryAccount extends BasicAccount{ | |
@Override | |
public void yield() { | |
throw new UnsupportedOperationException("Salary account can't yield"); | |
} | |
} | |
public static void main(String[] args) { | |
List<BasicAccount> accountList = new AccountDAO().getAllAccounts(); | |
accountList.forEach(account -> account.yield()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment