Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.

Slides:



Advertisements
Similar presentations
1 Object-oriented design Part 2: OO tools & UML. 2 CRC cards Design tool & method for discovering classes, responsibilities, & relationships Record on.
Advertisements

CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
I NHERITANCE Chapter 10. I NHERITANCE Mechanism for enhancing existing classes You need to implement a new class You have an existing class that represents.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Chapter 12 ATM Case Study, Part 1: Object-Oriented Design with the UML
 2009 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
 2008 Pearson Education, Inc. All rights reserved (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
 2008 Pearson Education, Inc. All rights reserved (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System UML.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Chapter 8 More Object Concepts
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Writing Classes (Chapter 4)
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
ATM Case Study Chapter 1-10 Optional Sections
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
1 Introduction to Classes and Objects Chapter 3 Introduction to Classes and Objects Chapter 3.
Dale Roberts Object Oriented Programming using Java - OOD to OOP: ATM Case Study Dale Roberts, Lecturer Computer Science, IUPUI
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
Chapter 4 Introduction to Classes, Objects, Methods and strings
 2006 Pearson Education, Inc. All rights reserved Polymorphism, Interfaces & Operator Overloading.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
Java How to Program, 9/e © by Pearson Education, Inc. All Rights Reserved.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
 2005 Pearson Education, Inc. All rights reserved. 1 Classes and Objects: A Deeper Look.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
 2007 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Class Inheritance Part I
ATM OO Design and Implementation Case Study
Unified Modeling Language (UML)
An Introduction to Inheritance
Section 11.1 Class Variables and Methods
Object-Oriented Programming: Polymorphism
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Object-Oriented Programming: Polymorphism
Chapter 9 Object-Oriented Programming: Inheritance
Lecture 22 Inheritance Richard Gesick.
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Java Topics Chapter 9
Slides by Steve Armstrong LeTourneau University Longview, TX
Chapter 20 Object-Oriented Analysis and Design
Presentation transcript:

Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.

13.1 Introduction Section 13.2 shows how to convert class diagrams to Java code. Section 13.3 tunes the design with inheritance and polymorphism. Section 13.4 presents a full Java code implementation of the ATM software. (C) 2010 Pearson Education, Inc. All rights reserved.

13.2 Starting to Program the Classes of the ATM System (cont.) Navigability The class diagram in Fig further refines the relationships among classes in the ATM system by adding navigability arrows to the association lines. Programmers use navigability arrows to determine which objects need references to other objects. Associations that have navigability arrows at both ends or have none at all indicate bidirectional navigability— navigation can proceed in either direction across the association. (C) 2010 Pearson Education, Inc. All rights reserved.

13.2 Starting to Program the Classes of the ATM System (cont.) Implementing the ATM System from Its UML Design We are now ready to begin implementing the ATM system. Convert the classes in the diagrams of Fig and Fig into Java code. The code will represent the “skeleton” of the system. (C) 2010 Pearson Education, Inc. All rights reserved.

13.2 Starting to Program the Classes of the ATM System (cont.) Four guidelines for each class: –1. Use the name located in the first compartment to declare the class as a public class with an empty no-argument constructor (Fig. 13.3). –2. Use the attributes located in the second compartment to declare the instance variables (Fig. 13.4). –3. Use the associations described in the class diagram to declare the references to other objects (Fig. 13.5). –4. Use the operations located in the third compartment of Fig to declare the shells of the methods (Fig. 13.6). If we have not yet specified a return type for an operation, we declare the method with return type void. Refer to the class diagrams of Figs –12.21 to declare any necessary parameters. (C) 2010 Pearson Education, Inc. All rights reserved.

13.3 Incorporating Inheritance and Polymorphism into the ATM System To apply inheritance, look for commonality among classes in the system. Create an inheritance hierarchy to model similar (yet not identical) classes in a more elegant and efficient manner. Modify class diagram to incorporate the new inheritance relationships. Translate updated design into Java code. (C) 2010 Pearson Education, Inc. All rights reserved.

13.3 Incorporating Inheritance and Polymorphism into the ATM System (cont.) Polymorphism provides the ATM with an elegant way to execute all transactions “in the general.” The polymorphic approach also makes the system easily extensible. To create a new transaction type, just create an additional Transaction subclass that overrides the execute method with a version of the method appropriate for executing the new transaction type. (C) 2010 Pearson Education, Inc. All rights reserved.

13.4 ATM Case Study Implementation Consider the classes in the order in which we identified them in Section 12.3— ATM, Screen, Keypad, CashDispenser, Deposit-Slot, Account, BankDatabase, Transaction, BalanceInquiry, Withdrawal and Deposit. Apply the guidelines discussed in Sections 13.2–13.3 to code these classes based on how we modeled them in the UML class diagrams of Figs and (C) 2010 Pearson Education, Inc. All rights reserved.

13.5 ATM Case Study Implementation (cont.) Our ATM design does not specify all the program logic and may not specify all the attributes and operations required to complete the ATM implementation. – This is a normal part of the object-oriented design process. As we implement the system, we complete the program logic and add attributes and behaviors as necessary to construct the ATM system specified by the requirements document in Section (C) 2010 Pearson Education, Inc. All rights reserved.

Class CashDispenser Class CashDispenser (Fig ) represents the cash dispenser of the ATM. Constant INITIAL_COUNT indicates the initial count of bills in the cash dispenser when the ATM starts (i.e., 500 ). The class trusts that a client (i.e., Withdrawal ) calls dispenseCash only after establishing that sufficient cash is available by calling isSufficientCashAvailable. Thus, dispenseCash simply simulates dispensing the requested amount without checking whether sufficient cash is available. (C) 2010 Pearson Education, Inc. All rights reserved.

Class DepositSlot Class DepositSlot (Fig ) represents the ATM’s deposit slot. DepositSlot has no attributes and only one method— isEnvelopeReceived (lines 8– 11)—which indicates whether a deposit envelope was received. (C) 2010 Pearson Education, Inc. All rights reserved.

Class Transaction Class Transaction (Fig ) is an abstract superclass that represents the notion of an ATM transaction. It contains the common features of subclasses BalanceInquiry, Withdrawal and Deposit. The class has three public get methods— getAccountNumber (lines 20–23), get-Screen (lines 26–29) and getBankDatabase (lines 32–35). – T hese are inherited by Transaction subclasses and used to gain access to class Transaction ’s private attributes. (C) 2010 Pearson Education, Inc. All rights reserved.

Class BalanceInquiry Class BalanceInquiry (Fig ) extends Transaction and represents a balance-inquiry ATM transaction. BalanceInquiry does not have any attributes of its own, but it inherits Transaction attributes accountNumber, screen and bankDatabase, which are accessible through Transaction ’s public get methods. (C) 2010 Pearson Education, Inc. All rights reserved.

Class Withdrawal Class Withdrawal (Fig ) extends Transaction and represents a withdrawal ATM transaction. Figure 13.9 models associations between class Withdrawal and classes Keypad and CashDispenser, for which lines 7–8 implement reference-type attributes keypad and cashDispenser, respectively. (C) 2010 Pearson Education, Inc. All rights reserved.

Class Deposit Class Deposit (Fig ) extends Transaction and represents a deposit transaction. Lines 7–8 create reference-type attributes keypad and depositSlot that implement the associations between class Deposit and classes Keypad and DepositSlot modeled in Fig Line 9 declares a constant CANCELED that corresponds to the value a user enters to cancel. (C) 2010 Pearson Education, Inc. All rights reserved.

Class ATMCaseStudy Class ATMCaseStudy (Fig ) is a simple class that allows us to start, or “turn on,” the ATM and test the implementation of our ATM system model. (C) 2010 Pearson Education, Inc. All rights reserved.