0% found this document useful (0 votes)
2 views30 pages

Class Diagram

The document provides a comprehensive overview of class diagrams in object-oriented modeling, detailing the steps for developing them, including identifying object classes, associations, and attributes. It explains various relationships between classes such as associations, composition, aggregation, and generalization/specialization, along with UML cardinality notations. Additionally, it includes examples of class diagrams and sequence diagrams to illustrate the concepts discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views30 pages

Class Diagram

The document provides a comprehensive overview of class diagrams in object-oriented modeling, detailing the steps for developing them, including identifying object classes, associations, and attributes. It explains various relationships between classes such as associations, composition, aggregation, and generalization/specialization, along with UML cardinality notations. Additionally, it includes examples of class diagrams and sequence diagrams to illustrate the concepts discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Modeling Structure –

Class Diagram
Class Diagram
Object class name

Attributes

Operations
(behaviors) to
fulfill the
class’s
responsibilities
.
Steps in Developing a Class
Diagram

Identify object classes


Identify associations
Identify object attributes
Organize object classes using
inheritance
Describe communication using
sequence diagrams
Group classes
Class Diagram

Class
attributes

operations

subClass subClass subClass

Object Object Object


Relationships between classes
1. Associations
2. Composition/Aggregation
3. Generalization/Specialization
Associations
– relationship between classes
– E.g, Employee works in Department
– Specifies how many instances of one class may
relate to a single instance of another class

• 1-to-1 association • Optional association (0, 1,


or many)
– Company has President – Customer owns Credit
Card
• 1-to-many association • Many-to-Many
association
Showing Association

An Association between two classes is shown by a


simple line. It can be given a descriptive name and
augmented with the Role played by each class and
with the Cardinality of the relationship.
Associations
Country City
Has-capital
name:String name:String

One-to-one association

StickyNote
Workorder
* x: Integer
y: Integer
schedule() z: Integer

One-to-many association
[From Bruegge, 2000]
Many-to-Many Associations

Mechanics Plane
* Work on *

[From Bruegge, 2000]


Sample UML Cardinality Notations
Association with Multiplicity Association
Multiplicity Notation
Meaning
Works for 1
1 Employee Department
An employee
Exactly 1 or works for one
and only one
Works for department.
leave blank Employee Department

Has 0..1 An employee has


Zero or one 0..1 Employee Spouse either one or no
spouse.

Makes 0..*
0..* Customer Payment
A customer can
Zero or or make no payment
more up to many
Makes * payments.
* Customer Payment

Offers 1..* A u niversity


One or more 1..* University Course offers at least 1
course up to
many courses.
Has
Specific scheduled 7..9 A team has either
range 7..9 Team Game 7, 8, or 9 games
scheduled
Composition and Aggregation Hierarchies
• Whole/Part Relationships
– Show components of more complex class
– Composition is stronger relationship than
aggregation
• Composition Hierarchy
– Whole and part objects are created, live,
die together
– Often also has a physical association
– Association between instances
• Aggregation Hierarchy
– Part objects of aggregate object may be
created and deleted independently of
aggregate object
– Often used for more abstract whole/part
Showing Aggregation

If one class is contained within another a solid


diamond is placed on the line next to the containing
class. This is termed by value, Class2 it
essentially a value within Class1.

If the relationship is a simple aggregation then


an empty diamond is used. This is termed by
reference, Class1 refers to Class2.
Aggregation Example

Car

Engine Seating Wheel


Aggregation Example
Automobile
Engine serial number
horsepower year
volume manufacturer
model
on color
off weight
drive
purchase

4,6 2,4 *

Wheel Brakelight Door Battery


diameter amps
number of bolts open volts
on close
off charge
discharge
Composition Example
Generalization / Specialization Hierarchy

• Some classes are similar but not identical


– Have some attributes in common, others
different
• Common attributes abstracted into
generalized class(superclass) – E.g.,
Account (Account number, Balance)
• Different attributes are properties of
specialized class(subclass) – E.g., Savings
Account (Interest)
• IS A relationship between subclass and
superclass – Savings Account IS A Account
‘generalization’ showing inheritance

Super class

Sub class

Inheritance is shown by a line from the sub-class


to the super-class with an arrow pointing to the
super class.
Example : Inheritance
STAFF

Name
Address
Salary
No. staff

Director Manager MKT Staff

Establish Goal() Make a Plan() Set MKT Campaign()


UML Representation of
Generalization/Specialization
Person

last name
first name
birthdate
gender

walk()
jump()
talk()
sleep()
eat()
etc.()
Arrowhead indicates
generalization/specialization
relationship

Student Teacher

GPA rank
classification

enroll() lecture()
displayGPA()
Inheritance Example

Cell

BloodCell MuscleCell NerveCell

Red White Smooth Striate Cortical Pyramidal

[From Bruegge, 2000]


Example : Class Diagram
Actuator
startUp
shutDown

Light Heater Cooler Temperature


off 1 1
on
*

1 11
Environmental Controller SystemLog
Define_climate Display
Terminate_climate
RecordEvent
Example : Class Diagram
Object /Class Association Generalization

Aggregation
Library Item
0..* No. Copies
ShelfNo
Status
User Borrows Title
Issue
Address Return
Member# Shelve
Name
Subscribe
Unsubscribe

Recorded Media
External Reader Borrower
Ext. Library Name Items Borrowed
Book CAL Package
Maximum Loans
Author Distributor
ISBN
Course Text
Pub. Date
Publisher
Summary – Class Relationship
GENERALIZATIO Plan
ASSOCIATION N/ INHERITANCE
PlanAnalyst

1..2 GrowingPlan GardeningPlan

analyzes
1..*

PlanMetrics

FruitGrowingPlan

AGGREGATION COMPOSITION
Controller * 1 Cooler
Food

* *
1 1
1..23
*
* 1
Vitamin Calorie
Light Heater
Member Services System Class Diagram
Member
Member-Number
Member-Name
Member-Status
Member-Street-Address
Member-PO-Box
Member-City
Member-State
Member-Zip-Code

persistent

<<actor>> <<actor>>
Potential Member Club Member <<actor>>
Past Member
Member-Date-Of-Last-Order
Member-Daytime-Phone-Number Expiration-Date Agreement
persistent Member-Credit-Card-Expire-Date
Member-Credit-Card-Number Agreement-Number
Member-Credit-Card-Type persistent Agreement-Expire-Date
Member-Balance-Due Agreement-Active-Date
Member-Bonus-Balance-Available 1..* Fulfillment-Period
Audio-Category-Preference Required-Number-Of-Credits
Audio-Media-Preference
1 Date-Enrolled binds
Has Email-Address 1
purchased Game-Category-Preference persistent
0..* Game-Media-Preference
Product Number-Of-Credits-Earned
Member Ordered Product
Privacy-Code
Product-Number Video-Category-Preference
UPC- Quantity-Ordered Video-Media-Preference Transaction
Quantity-In-Stock Quantity-Shipped
Product-Type Quantity-Backordered 1 Conduct Transaction-Reference-Number
Suggested-Retail-Price 1 Sold as Purchase-Unit-Price s Transaction-Date
Default-Unit-Price Credits-Earned persistent Transaction-Type
Current-Special-Unit-Price 0..* Transaction-Description
Current-Month-Units-Sold 0..* Transation-Amount
Current-Year-Units-Sold persistent
Total-Lifetime-Units-Sold 1
1..* persistent
persistent Places

0..*
Member Order Return
Sells
1 Order-Number
Merchandise Title Order-Creation-Date
Promotion Order-Fill-Date persistent
Merchandise-Name Title-Of-Work Shipping-Address-Name
Merchandise-Description Title-Cover 1..* Promotion-Number Shipping-Street-Address
Merchandise-Type Catalog-Description Promotion-Release-Date Generate Shipping-City
Unit-of-Measure Copyright-Date Promotion-Status 0..1 s Shipping-State
Entertainment-Company Feature 0..* Shipping-Zip-Code
s Promotion-Type 0..* Shipping-Instructions
Credit-Value
persistent Order-Sub-Total
Order-Sales-Tax
persistent Order-Shipping-Method
persistent Order-Shipping-&-Handling-Cost
Order-Status
Order-Prepaid-Amount
Order-Prepayment-Method

persistent
Audio Tilte Video Title Game Title
Artist Producer Manufacturer
Audio-Category Director Game-Category
Audio-Sub-Category Video-Category Game-Sub-Category
Number-Of-Units-In-Package Video-Sub-Category Game-Platform
Audio-Media-Code Closed-Captioned Game-Media-Type
Content-Advisory-Code Language Number-Of-Players
Running-Time Parent-Advisory-Code
Video-Media-Type
persistent Video-Encoding
Screen-Aspect
MPA-Rating-Code persistent

persistent
Sequence Diagram
Order Entry Order Order Line Stock Item Reorder Delivery
window Item Item
prepare()
prepare()
check()

[check=“true”]
remove()
needsToReorder()

[needsToReorder=“true”]
enter new

[check=“true”]
enter new
Order OrderLine ReOrderItem
orderNumber itemnumber itemnumber
date quantity quantity
etc… etc… etc…
prepare() prepare()
enter new()

StockItem
DeliveryItem
orderNumber
minQuantity is_for deliveryadress
date quantity
etc… etc…
needsToReorder(): enter new()
boolean
check(): boolean
remove()
Computer: PrintServer: Printer: Queue:
Computer PrintServer Printer Queue
User: User
print
(filename)
print(file)
[printer free]
print(file)

[printer busy]
store(file)
Computer PrintServer Printer
status(): integer
print(file)
uses
print(filename) print(file)

Managed by

Queue

store(file)
Recap
• After studying this chapter we learned
to:
– Understand how to structure
requirements with class diagram.
– Explain the element of class diagrams
– Construct class diagrams.

You might also like