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?
- A. Liskov substitution; make Account final
- B. Interface segregation; split getters and setters into two interfaces
- C. Open/closed; add a strategy for every withdrawal type
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- In GRASP, which pattern describes creating a class such as OrderPersistenceService that has no counterpart in the domain, so that domain…
- In a Kubernetes service mesh, each pod runs an extra proxy container beside the application that handles mTLS, retries and metrics for all…
- Match each caching write policy with its behaviour. P. Write-through Q. Write-behind (write-back) R. Write-around 1. Writes go only to the…
- Pull requests A and B each pass CI against main and are merged one after the other, after which main fails to build: A renamed a function…
- On main you run git merge f1 f2 f3, where the three branches touch different files and none conflict. What results?
- A developer on Windows opens a repository created on Linux, edits one line of a file, and git diff shows every line changed. What is the…