Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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