Class Diagrams

advertisement
Class Diagrams
Tutorial
Conceptual class diagram-Online
Bookstore
• An Informal Description
"The system is an online, web-based bookstore. The
bookstore sells books, music CDs, and software. Typically, a
customer first logs on to the system, entering a customer ID
and password. The customer can then browse for items or
search by keyword(title, Author , Publisher, ISBN). The
customer puts some of the items into a "shopping cart"
which keeps track of the desired items. When the customer
is done shopping, he/she confirms the order, shipping
address, and billing address. The bookstore system then
issues a shipping order, bills the customer, and issues an
electronic receipt. At the end of the transaction, the
customer logs off."
Online Bookstore
• A Scenario
1. User logs on.
2. System displays welcome message and requests customer ID and password.
3. User enters customer ID and password.
4. System validates the ID and password.
5. User searches for a items by browsing or keyword search
6. System displays information about the title.
7. User selects a title to buy
8. System adds items to the customer's shopping cart
9. [Repeat 5-8 until done]
10. User is done with shopping
11. System displays shopping cart, shipping address, and billing address
12. User confirms order and payment method.
13. System processes order, notifies warehouse for shipping, and issues an electronic
receipt.
14. User logs
Identify the classes
• Look for important nouns: Objects, people,
organizations, places, events, concepts.
From the given scenario
• OnLineBookstore, Customer, Book, MusicCD,
Software, order, shoppingCart are the classes
Class Attributes
• Analyze the requirements to find the attributes
of each class
• A Customer has a name, customerID,
password, shippingAddress, and
billingAddress.
An Address has a street, city, state, country,
and postalCode.
Relationships
• Analyze the requirements to find relationships between classes.
• Draw relationships as lines between class boxes.
• Annotate the relationships: How many OrderItems for each Order
are possible?
• Use symbols to indicate the kind of relationship: Generic,
aggregation (has-a or owns-a), inheritance (is-a).
• For generic relationships, use an arrowhead to indicate whether the
relationship is navigable: Does the source object know about the
destination object?
• After identifying candidate classes, see if there are any
commonalities between them that might be an IS-A relationship. It
may make sense to factor the common parts into a super class, and
create an inheritance relationship:
Finding Relationships
Class diagram
Conceptual class diagramProgramming Language
Based on the following description of part of the syntax of a
programming language, construct a class diagram showing
the structure of programs written in the language and show
the types of associations between the classes.
- A module consists of a collection of features. A feature can
either be a variable, a routine or a nested module. Routines
consist of a declaration part and a statement part. Features
local to the routine can be declared in the declaration part,
and the statement part consists of a non-empty sequence
of statements. Statements can be loops, conditionals or
assignments, and each assignment contains a reference to
the variable which is being assigned to.
Identify the classes
•
•
•
•
•
•
•
•
•
•
Feature
Variable
Routine
Module
DeclarationPart
Statement Part
Statement
Loop
Conditional
Assignment
Solution
Class diagram
Hospital Information System
• Informal Description
• "The system is a hospital information system. A
hospital has doctors and patients. Each patient is
assigned to one doctor, but a doctor can have any
number of patients. Patients check in to the hospital
and assigned a doctor if they don't already have one.
While in the hospital, doctors record various
observations about each patient at various times.
Examples of observations are blood pressure and
temperature. The hospital keeps track of all the
observations for a given patient until they check out of
the hospital."
Scenario
• Patient checks in to hospital.
• Hospital assigns doctor to the patient.
• The doctor records a blood pressure
measurement for the patient.
• The doctor records a temperature for the patient.
• The doctor prescribes medicine for the patient's
condition.
• The patient checks out of the hospital.
Download