Is this precondition a violation of the Liskov Substitution Principle
问题 I have 3 classes, Account , CappedAccount , UserAccount , CappedAccount , and UserAccount both extend Account . Account contains the following: abstract class Account { ... /** * Attempts to add money to account. */ public void add(double amount) { balance += amount; } } CappedAccount overrides this behavior: public class CappedAccount extends Account { ... @Override public void add(double amount) { if (balance + amount > cap) { // New Precondition return; } balance += amount; } } UserAccount