![]() 10.18 Class diagram modeling generalization of superclass Transaction and subclasses BalanceInquiry, Withdrawal and Deposit. We place the common functionality in a superclass, Transaction, that classes BalanceInquiry, Withdrawal and Deposit extend.įig. Figure 10.17 reveals commonality among the transaction classes, so using inheritance to factor out the common features seems appropriate for designing classes BalanceInquiry, Withdrawal and Deposit. Clearly, BalanceInquiry, Withdrawal and Deposit represent types of transactions. Each class contains operation execute, which the ATM invokes to perform the transaction. Each class requires attribute accountNumber to specify the account to which the transaction applies. Note that these classes have one attribute ( accountNumber) and one operation ( execute) in common. Figure 10.17 shows the attributes and operations of classes BalanceInquiry, Withdrawal and Deposit. Rather than create one class to represent all transaction types, we decided to create three individual transaction classes- BalanceInquiry, Withdrawal and Deposit-to represent the transactions that the ATM system can perform. In Section 3.9, we encountered the problem of representing a financial transaction in the system. Finally, we demonstrate how our updated design is translated into Java code. We then modify our class diagram to incorporate the new inheritance relationships. We create an inheritance hierarchy to model similar (yet not identical) classes in a more elegant and efficient manner. To apply inheritance, we first look for commonality among classes in the system. We now revisit our ATM system design to see how it might benefit from inheritance. If (enteredPassword.Learn More Buy 10.8 (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System String enteredPassword = bankScanner.nextLine() Scanner bankScanner = new Scanner(System.in) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |