16 - Problem Decomposition - Revisited
16 - Problem Decomposition - Revisited
(Again):
Object Oriented Design
There’s more…?
zombie[3]
zombie[1]
zombie[4]
zombie[5]
zombie[2]
zombie[0]
3
What are the Nouns?
4
Initial Diagram
5
UML Diagram
6
UML with Some Data Types Added
7
Simplified Bank Customer:
Instance Variables:
Let’s ignore some of the complexity and Name
assume a bank employee is running our Address
program. The employee can work with SSN
Customers and Accounts. Accounts
Methods:
For one scenario, assume a person comes Add Customer
into our bank and wants to open an account. Delete Customer
This person is not yet a customer, so the
bank employee needs to add them as a Account:
customer and then open the account for Instance Variables:
them, and make that first deposit into the Balance
account. Account Number
Customer
(By the way, this way of thinking about a Methods:
problem, by looking at scenarios, is called Open Account
developing use cases.) Close Account
Deposit
Our job is to first define the API. Withdraw
Transfer Money
8
Simplified Bank Customer:
Instance Variables:
Our job is to first define the API. Name
Address
SSN
What will our methods need in Accounts
order to run, and what will they Methods:
return to the client program? Add Customer
Delete Customer
Account
Account(Customer customer, long acctNumber)
Account(Customer customer, long acctNumber,
double initAmt)
Account DeleteAccount()
Deposit(double amount)
Withdraw(double amount)
TransferMoney(double amount, Account account)
// Comment: the account parameter is the account
// transferred to
10
Instance Variables
Now that the API is defined, we need to make sure our
instance variables are adequate to support the API.
Account:
Balance
Account Number
Customer
11
Instance Variables
Customer:
String firstName
String lastName
String SSN
String street
String city
String state
String zipCode
Account [] accounts
//Comment: Let’s say a customer can have a maximum of 20 accounts
Account:
double Balance
long accountNumber
Customer customer
12
Simplified Bank
13
Summary