CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 1
MDERE
SE
• The OO model closely resembles the problem domain– Base your model on the objects in the
problem domain• Iteratively refine the high-level model
until you have an implementation– Attempt to avoid big conceptual jumps
during the development process
CSE870: UML Classes 1
The OO Solution
MDERE
SEObjects
CSE870: UML Classes 2
J. Q. Public
VISA
123 4567 887766 998
J. Q. Public
Drivers LicenseState of Michigan
A-12345603-12-63
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 2
MDERE
SE
J. Q. Public
VISA
123 4567 887766 998
J. Q. Public
Drivers LicenseState of Michigan
A-12345603-12-63
Person objects
Card objectsAttributes
heightwidthid-number
Operationsissuechange
Card class
Person classAttributes
nameageheightweight
Operationsmovechange-job
abstracts to
Attributes and Operations
CSE870: UML Classes 3
MDERE
SE
• Identity– Discrete and distinguishable entities
• Classification– Abstract entities with the same structure (attributes) and
behavior (operations) into classes• Polymorphism
– The same operation may behave differently on different classes• Inheritance
– Sharing of attributes and operations based on a hierarchical relationship
CSE870: UML Classes 4
Characteristics of Objects
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 3
MDERE
SE
The Class Diagrams
CSE870: UML Classes 5
MDERE
SE
• Something that makes sense in the application context (application domain)– J.Q. Public– Joe’s Homework Assignment 1– J. Q. Public’s drivers license
• All objects have identity and are distinguishable
• NOT objects– Person– Drivers license
CSE870: UML Classes 6
Objects
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 4
MDERE
SE
• Describes a group of objects with:– similar properties (attributes), – common behavior (operations), – common relationships to other classes, and – common semantics
• Person• J. Q. Public• Joe Smith• D. Q. Public
– Card• Credit card• Drivers license• Teller card
CSE870: UML Classes 7
Classes
MDERE
SE Class Diagrams
CSE870: UML Classes 8
Class with attributes Objects with values
Objects have an identity
Do not explicitly list object identifiersSSN OK!
Class diagram Instance diagram
age: integer
Person D. Q. Public:
age= 32
Person J. Q. Public:
age= 35
Person
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 5
MDERE
SE Examples
CSE870: UML Classes 9
MDERE
SEOperations and Methods
• Transformation that can be applied to or performed by an object
• May have arguments
CSE870: UML Classes 10
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 6
MDERE
SE Object Notation - Summary
CSE870: UML Classes 11
MDERE
SE
• Conceptual connection between classes– A credit card is issued-by a bank– A person works-for a company
CSE870: UML Classes 12
Associations
Class diagrams
Credit Card BankIssued-by
Person CompanyWorks-for
J.Q. Public:
Age=35
Person Michigan State Univ:Company
Works-for Instance diagram
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 7
MDERE
SE
• There is no direction implied in an association (Rumbaugh - OMT)
CSE870: UML Classes 13
Associations are Bi-directional
Countryname
Drivers-licenselic.-number: integer
Personname
Cityname
Has-capital
Is-issued
MDERE
SE
• Unified adds a direction indicator– Inconsistently used
CSE870: UML Classes 14
Associations Can Have Direction
Countryname
Drivers-licenselic.-number: integer
Personname
Cityname
Has-capital
Is-issued
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 8
MDERE
SE
• One object can be related to many objects through the same association
CSE870: UML Classes 15
Multiplicity
One person holds one credit card name: String
Person
card-number: integer
Credit-cardHolds
One person can hold zero or more credit cards name: String
Person
card-number: integer
Credit-cardHolds 0..*
MDERE
SEMultiplicity (Cont.)
CSE870: UML Classes 16
•One person can hold zero or more credit cards (0..*) •Each card has zero or one holder (0..1)
name: Stringage: integer
Person
card-number: integer
Credit-cardHolds 0..*0..1
Holds
Holds
:JQPublic:Person
name= J. Q. Publicage=35
:DQPublic:Person
name= D. Q. Publicage=32
card-number=123 456 789
Card789:Credit-Card
card-number=111 222 333
Card123:Credit-Cardcard-number=444 555 666
Card456:Credit-Card
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 9
MDERE
SE
• Ternary association– Project, language, person
• Seldom needed (and should be avoided)
CSE870: UML Classes 18
Higher order associations
Language
Person
Project1..*
1..*
1..*
J. Q. Public:PersonAge=35
Compiler: ProjectC++ :Language
TicTacToe:ProjectLISP:Language
Instance of ternaryassociation
MDERE
SE
• Associations can have properties the same way objects have properties
CSE870: UML Classes 19
Link Attributes
How to represent salary and job title?name: String
age: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..*
Use a link attribute!name: Stringage: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..*
salary: integerjob-title: String
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 10
MDERE
SEFolding Link Attributes
CSE870: UML Classes 20
Why not this?
Salary and job title are properties of the job notthe person
In this case, a link attribute is the only solution
name: Stringage: integerSSN: integer
address: Stringsalary: integerjob-title: String
Person
name: Stringaddress: String
CompanyWorks-for0..*
name: Stringage: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..*
salary: integerjob-title: String
0..*
MDERE
SE
• Attach names to the ends of an association to clarify its meaning
CSE870: UML Classes 21
Role Names
name: Stringage: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..* 0..*
salary: integerjob-title: String
employeremployeeboss
workerManages0..*
0..1
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 11
MDERE
SE
• A special association, the is-part-of association– A sentence is part of a paragraph (a
paragraph consists of sentences)– A paragraph is part of a document (a
document consists of paragraphs)
CSE870: UML Classes 22
Aggregation
Aggregation symbol
Document Paragraph Sentence0..* 0..*
MDERE
SE
• Often used in parts explosion
CSE870: UML Classes 23
Aggregation (Cont.)
Car
Wheel Body Gearbox Engine
Door Hood Trunk Piston Valve Crankshaft
0..*1..* 1..*
4
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 12
MDERE
SE Generalization and Inheritance
• The is-a association– Cards have many
properties in common– Generalize the common
properties to a separate class, the base-card
– Let all cards inherit from this class, all cards is-a base-card (plus possibly something more)
CSE870: UML Classes 24
issue()revoke()
height: integerwidth: integer
thickness: integerid-number: integer
Card
expire()
class: vehicleissued: dateexpires: date
Drivers License
expire()
issued: dateexpires: date
ID Card
validate()
credit-limit: integerissued: date
Credit Card
MDERE
SE
name
City
name
Airline
namelicense
Pilot
name
Passenger
heat()clean()
name
Airport
cancel()delay()
dateflight #
Flight
heat()refuel()clean()
modelserial #
hours flown
Plane
reserve()
locationSeat
Based-In 0..*
Departs
Works-for
Arrives Used-For
Certified-On
Owns
Located-In
0..*
OffersPilots
Confirmed-for
0..*
0..*
0..*
1..*
0..*
0..*0..*
0..*
30..*
Example
CSE870: UML Classes 25
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 13
MDERE
SE
• Can you use the phrase is-part-of or is-made-of• Are operations automatically applied to the parts
(for example, move) - aggregation• Not clear what it should be……
CSE870: UML Classes 26
Aggregation Versus Association
Company DepartmentDivision
Person
0..*Works-for
0..* 0..*
MDERE
SEAggregation Versus Inheritance
• Do not confuse the is-a relation (inheritance) with the is-part-of relation (aggregation)
• Use inheritance for special cases of a general concept
• Use aggregation for parts explosion
CSE870: UML Classes 27
Car
Wheel
Body
Gearbox
Engine
4
Minivan Compact Jeep
Roll Bar
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 14
MDERE
SE
• A recursive aggregate contains (directly or indirectly) an instance of the same kind of aggregate
CSE870: UML Classes 28
Recursive Aggregates
Program
SimpleStatement
CompoundStatement
Block0..*
MDERE
SE
CSE 435: Software Engineering
Class diagram Metamodel I
Eclipse.org
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 15
MDERE
SE
CSE 435: Software Engineering
Class diagram Metamodel II
Science direct
MDERE
SE
CSE 435: Software Engineering
Use Case Metamodel I
Image: Science Direct: ``Visual Modeling for Software Intensive Systems, Kooper et al, 2006.
uu: use case association relationship_i: includes_e: extends_g: generalization
aa: actor relationship
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 16
MDERE
SE
CSE 435: Software Engineering
Use Case Metamodel II
Image: Jot.fm
MDERE
SEMeta Model Architecture
• M3: language for describing meta-models (MOF: Meta Object Facility)
• M2: meta model for a given modeling language
• M1: class diagram
• M0: instance of class diagram
CSE870: UML Classes 34
M3
M2
M1
M0
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 17
MDERE
SE
• Facebook: • http://upload.wikimedia.org/wikipedia/co
mmons/c/c6/Facebook_Metamodel_Represented_in_UML_notation_v01.jpg
CSE870: UML Classes 35
Interesting/Fun Metamodels
CSE870: UML Classes 36
CSE870: Cheng
CSE870: Advanced Software Engineering (Cheng) 18
MDERE
SEObject Modeling Summary
• Classes– Name– Attributes– Operations
• Associations– Roles– Link attributes
• Aggregation• Inheritance
CSE870: UML Classes 37