Skip to content

Instantly share code, notes, and snippets.

@luissilvazup
Created June 17, 2020 21:19
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 luissilvazup/43c3e70d8eaf3b1cffccb20e3acfa011 to your computer and use it in GitHub Desktop.
Save luissilvazup/43c3e70d8eaf3b1cffccb20e3acfa011 to your computer and use it in GitHub Desktop.
LSP Problem
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