Title: Glenn David Blank Computer Science
1Object-oriented design from problem
descriptionto class diagram
- Glenn David Blank Computer Science Engineering
Department - Lehigh University, Bethlehem, PA, USA
With support from the National Science
Foundation (Grants No. EIA-0087977 and 0624553)
and the Pennsylvania Infrastructure Technology
Alliance
2(No Transcript)
3From problem description to class diagram (in
nine steps)
- 1. Read the problem description at least twice.
- Ask questions about anything you dont understand
or needs more explanation. - The ATM verifies whether the customer's card
number and his her PIN (a number) are correct. If
it is, then the customer can check the account
balance, deposit cash, and withdraw cash.
Checking the balance simply displays the account
balance. Depositing asks the customer to enter
the amount, then updates the account balance.
Withdraw cash asks the customer for the amount to
withdraw if the account has enough cash, the
account balance is updated. The ATM prints the
customers account balance on a receipt.
4Sentence grammar analysis
- 2. Put an S next to each subject, a V next to
each verb and an O next to each object. - The ATM verifies whether the customer's card
number and PIN are correct. - S V
O O O - If it is, then the customer can check the
account balance, deposit cash, - S V
O V O
- and withdraw cash. Checking the balance displays
the account balance. - V O S
O V O - Depositing asks the customer to enter an amount,
then updates the balance. - S V O V
O V
O - Withdrawing asks the customer for the amount to
withdraw if the account has - S V O
O V S
V - enough cash, the balance is updated. The ATM
prints the customers - O S V
S V O - account balance on a receipt.
- O O
5Analyze subjects and objects
- The ATM verifies whether the customer's card
number and PIN are correct. - S V
O O OIf it
is, then the customer can check the account
balance, deposit cash, and withdraw cash. - S
V O V
O V O - Checking the balance simply displays the account
balance. - S O
V O - Depositing asks the customer to enter the
amount, then updates the account balance. - S V O
V O V
O Withdraw cash asks the customer
for the amount to withdraw if the account has
enough cash, - S O V O
O V
S V O - the account balance is updated. The ATM prints
the customers account balance on a receipt. - O V
S V
O O - 3. Analyze each subject and object as follows
- Does it represent a person performing an action?
Then is an actor, R. - Is it also a verb (such as deposit)? Then it
may be a method, M. - Does a subject take a simple value, such as
color (string) or money (number)? Then it is
probably an attribute, A. - Which remaining unmarked noun occurs most
frequently? Make it C for class. - In Eclipse, draw a class for your first class.
A
C
A
R
M
A
A
M
M
M
R
A
M
A
A
A
M
A
A
M
R
R
A
A
A
M
A
A
C
6(No Transcript)
7Analyze methods and attributes
- 4. If a verb has a non-actor object its a
method, M - 5. Distinguish attributes, A, and parameters, P
- If it doesnt distinguish instances of a class or
store information about objects, its probably a
parameter, not an attribute - Add attributes to a class in the UML class
diagram - Add methods in the class diagram
- While adding methods, include the parameters
- See the return type of your methods
- get methods take the type of the attribute
returned - set methods take void return type
- compute methods take the type of the computed
value - Methods that answer true/false questions take
boolean type
8Constructors
- 6. Design one or more constructors for the class.
- A constructor creates an instance of a class.
- A constructor has the same name as the
classe.g., class Person has constructor
Person(). - A constructor has no return type, but may take
parametersto initialize attributes.
9Any more classes?
- 7. If any remaining class has no attributes,
its probably an attribute of another class - 8. Otherwise, add another class to the diagram
and go back to step 4 (analyze its methods and
attributes) - 9. Draw association links between the classes
- Check your design to make sure it makes sense!
10Lab exercise Design a movie ticket vending
machine
The movie ticket machine displays the movie
title, displays the show time (e.g. 2006-11-16
700pm), and displays the price of a ticket
(e.g. 8.50). A customer enters money (e.g. 20.50)
into the machine. The machine displays the
customers balance (e.g. 20.50). The customer
enters the number of tickets (e.g. 1) into the
machine. The machine prints the tickets, and
returns the customers balance (e.g. 12.00).
Print tickets also tracks the number of available
seats in the theater so it can tell the customer
when the available seats are sold out.