object-oriented modeling
TRANSCRIPT
Software Engineering (Cheng)
Software Engineering (Cheng) 1
Object-Oriented Modeling
One paradigm of development
Cheng:CSE 435: Software Engineering
The OO Solution
�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
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 2
Objects
Cheng:CSE 435: Software Engineering
J. Q. Public
VISA
123 4567 887766 998
J. Q. Public
Drivers LicenseState of Michigan
A-12345603-12-63
Person class
J. Q. Public
VISA
123 4567 887766 998
J. Q. Public
Drivers LicenseState of Michigan
A-12345603-12-63
Attributesnameageheightweight
Operationsmovechange-job
Attributesheightwidthid-number
Operationsissuechange
Person objects
Card objects Card class
abstracts to
Attributes and Operations
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 3
Characteristics of Objects
� 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
relationshipCheng:CSE 435: Software Engineering
The Class Diagrams
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 4
Objects� 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
Cheng:CSE 435: Software Engineering
Classes
� Describes a group of objects with similar properties (attributes), common behavior (operations), common relationships to other classes, and common semantics
� Persono J. Q. Public
o Joe Smitho D. Q. Public
§ Cardo Credit card
o Drivers license
o Teller card
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 5
Class Diagrams
Cheng:CSE 435: Software Engineering
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
Examples
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 6
Operations and Methods� Transformation that can be
applied to or performed by an object
� May have arguments
Cheng:CSE 435: Software Engineering
Object Notation - Summary
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 7
Associations
� Conceptual connection between classes§ A credit card is issued-by a bank
§ A person works-for a company
Cheng:CSE 435: Software Engineering
J.Q. Public:
Age=35
Person Michigan State Univ:Company
Works-for
Class diagrams
Instance diagram
Credit Card BankIssued-by
Person CompanyWorks-for
Associations are Bi-directional
� There is no direction implied in an association (Rumbaugh - OMT)
Cheng:CSE 435: Software Engineering
Countryname
Drivers-licenselic.-number: integer
Personname
Cityname
Has-capital
Is-issued
Software Engineering (Cheng)
Software Engineering (Cheng) 8
Associations Have Direction
� Unified adds a direction indicator§ Inconsistently used
Cheng:CSE 435: Software Engineering
Countryname
Drivers-licenselic.-number: integer
Personname
Cityname
Has-capital
Is-issued
Multiplicity
�One object can be related to many objects through the same association
Cheng:CSE 435: Software Engineering
One person holds one credit card
One person can hold zero or more credit cards
name: String
Person
card-number: integer
Credit-cardHolds
name: String
Person
card-number: integer
Credit-cardHolds 0..*
Software Engineering (Cheng)
Software Engineering (Cheng) 9
Multiplicity (Cont.)
Cheng:CSE 435: Software Engineering
•One person can hold zero or more credit cards (0..*) •Each card has zero or one holder (0..1)
Holds
Holds
name: Stringage: integer
Person
card-number: integer
Credit-cardHolds 0..*0..1
: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
Higher order associations
� Ternary association§ Project, language, person
� Seldom needed (and should be avoided)
Cheng:CSE 435: Software Engineering
Language
Person
Project1..*
1..*
1..*
J. Q. Public:PersonAge=35
Compiler: ProjectC++ :Language
TicTacToe:ProjectLISP:Language
Note: hexagons should berectangles to represent instances
Software Engineering (Cheng)
Software Engineering (Cheng) 10
Link Attributes
� Associations can have properties the same way objects have properties
Cheng:CSE 435: Software Engineering
How to represent salary and job title?
Use a link attribute!
name: Stringage: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..*
name: Stringage: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..*
salary: integerjob-title: String
Folding Link Attributes
Cheng:CSE 435: Software Engineering
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..*
Software Engineering (Cheng)
Software Engineering (Cheng) 11
Role Names
�Attach names to the ends of an association to clarify its meaning
Cheng:CSE 435: Software Engineering
name: Stringage: integerSSN: integer
address: String
Person
name: Stringaddress: String
CompanyWorks-for0..* 0..*
salary: integerjob-title: String
employeremployeeboss
workerManages0..*
0..1
Aggregation
�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)
Cheng:CSE 435: Software Engineering Aggregation symbol
Document Paragraph Sentence0..* 0..*
Software Engineering (Cheng)
Software Engineering (Cheng) 12
Aggregation (Cont.)
�Often used in parts explosion
Cheng:CSE 435: Software Engineering
Car
Wheel Body Gearbox Engine
Door Hood Trunk Piston Valve Crankshaft
0..*1..* 1..*
4
Composition
Cheng:CSE 435: Software Engineering
Building
Floor Facade HVAC
Door Roof Window
1..*
4Plumbing
1..*
Software Engineering (Cheng)
Software Engineering (Cheng) 13
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)
Cheng:CSE 435: Software Engineering
issue()revoke()
height: integerwidth: integer
thickness: integerid-number: integer
Card
expire()
class: vehicleissued: dateexpires: date
Drivers License
expire()
issued: dateexpires: date
Student ID Card
validate()
credit-limit: integerissued: date
Credit Card
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
Cheng:CSE 435: Software Engineering
Software Engineering (Cheng)
Software Engineering (Cheng) 14
Aggregation Versus Association
� 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……
Cheng:CSE 435: Software Engineering
Company DepartmentDivision
Person
0..*Works-for
0..* 0..*
Aggregation 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
Cheng:CSE 435: Software Engineering
Car
Wheel
Body
Gearbox
Engine
4
Minivan Compact Jeep
Roll Bar
Software Engineering (Cheng)
Software Engineering (Cheng) 15
Recursive Aggregates� A recursive aggregate contains (directly or indirectly) an instance of
the same kind of aggregate
Cheng:CSE 435: Software Engineering
Program
SimpleStatement
CompoundStatement
Block0..*
Class diagram Metamodel I
Cheng:CSE 435: Software EngineeringEclipse.org
Software Engineering (Cheng)
Software Engineering (Cheng) 16
Class diagram Metamodel II
Cheng:CSE 435: Software Engineering Science direct
Use Case Metamodel I
Cheng:CSE 435: Software EngineeringImage: 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
Software Engineering (Cheng)
Software Engineering (Cheng) 17
Use Case Metamodel II
Cheng:CSE 435: Software EngineeringImage: Jot.fm
Data flow diagram
Cheng:CSE 435: Software Engineering
Lexical analyzer
Semantic analyzer
Code generator
Code optimizer
source program token stream
abstract syntax tree
code sequence
object code
Compiler: BNF grammar
Pro
gram
mer
Software Engineering (Cheng)
Software Engineering (Cheng) 18
Possible Metamodel for DFD
Cheng:CSE 435: Software Engineering
Revised Metamodel for DFD
Cheng:CSE 435: Software Engineering
data from source
data to
target
Actor
0..*
PC:https://community.sparxsystems.com/white-papers/tag/metamodel
Software Engineering (Cheng)
Software Engineering (Cheng) 19
Object Modeling Summary� Classes
§ Name
§ Attributes
§ Operations
� Associations§ Roles
§ Link attributes
� Aggregation/Composition
� Inheritance
Cheng:CSE 435: Software Engineering