CS FundamentalsHardProduct-company placement

Code reads `if account.getBalance() >= amount: account.setBalance(account.getBalance() - amount)`. Which principle does this break, and what is the usual fix?

  1. A. Liskov substitution; make Account final
  2. B. Interface segregation; split getters and setters into two interfaces
  3. C. Open/closed; add a strategy for every withdrawal type
  4. D. Tell, don't ask; move the rule into account.withdraw(amount)

Correct answer: D. Tell, don't ask; move the rule into account.withdraw(amount)

The caller pulls the object's data, makes the decision itself and pushes the result back, so Account's invariant lives outside Account. 'Tell, don't ask' puts behaviour with the data: account.withdraw(amount) checks and updates itself.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic