0%
0 / 12 answered

Impact of Program Design Practice Test

12 Questions
Question
1 / 12
Q1

A bank is revising its Online Banking Application after an audit found inconsistent balance changes across features. The redesign emphasizes encapsulation using three classes: BankAccount, Transaction, and CustomerProfile. BankAccount stores balance as a private field and exposes deposit and withdraw methods that validate amounts and create a Transaction record for every change. CustomerProfile holds customer information and a list of accounts, but it cannot edit balances directly; it must call account methods. A separate TransferService moves money by calling withdraw on one BankAccount and deposit on another, relying on the built-in validation. The team also adds SavingsAccount extends BankAccount with a minimumBalance rule, overriding withdraw to block withdrawals that break the rule. This keeps account-specific constraints close to the account type. Readability improves because balance changes happen in one place, and maintainability improves because new rules are added by editing BankAccount or a subclass, not every feature. The team accepts a slight performance cost from extra method calls because it prevents invalid balance updates that would be expensive to fix later. Considering the class design, in the scenario, how does encapsulation improve data security?

Question Navigator