object modeling (2) chapter 3 (2) part 1: modeling concepts object-oriented modeling and design...
TRANSCRIPT
Object Modeling (2)
Chapter 3 (2)
Part 1: Modeling Concepts
Object-Oriented Modeling and Design
Byung-Hyun Ha ([email protected])
Lecture Outline
Introduction
Links and associations
Advanced link and association concepts
Generalization and inheritance
Remaining parts
Introduction
Class and objects A class is abstraction or specification of a group of similar objects e.g. Person vs. Joe, Mary, …
e.g. Every instance of our Vector has x, y, and length().
Person (Person)Joe Smith
24
(Person)Mary Sharp
52name: stringage: integer
public class Vector {
double x;double y;
double length() {double len = Math.sqrt(x * x + y * y);return len;
}}
Introduction
Association vs. links An association is abstraction or specification of a group of similar
links e.g. Has-capital
Country
name
City
name
Has-capital
(Country)Canada
(City)Ottawa
Has-capital
(Country)France
(City)Paris
Has-capital
(Country)Senegal
(City)Dakar
Has-capital
Introduction
Association vs. links (cont’) e.g. Intersects
Line
name
Point
name
Intersects
2+
Links and Associations (cont’)
Multiplicity specification How many instances of one class may related to a single
instance of an associated class
One or many
Optional
Numbers
Playboy Girlloves
Romanticist Girlloves
Boy Girlloves 1+3-5
Links and Associations
Multiplicity depends on problem e.g. tax collection application
e.g. auto workers’ union
It exposes hidden assumption built into the model
Person CompanyWorks-for
Person CompanyWorks-for
Advanced Link and Association Concepts
Role One end of association
Role name A name that uniquely identifies one end of an association
Person CompanyWorks-for
employee employer
User Directory container
contents
owner
authorized user
Advanced Link and Association Concepts
Role name All role names on the far end of associations attached to a class
must be unique The role name is a derived attribute of the source class
Role name for n-ary association Association of degree 3 or more cannot simply be traversed from
one end to another as binary associations can
Project Language
Person
Advanced Link and Association Concepts
Link attributes Properties of a link in an association
File UserAccessible by
access permission
/etc/termcap (read) John Doe/etc/termcap (read-write) Mary Brown/usr/doe/.login (read-write) John Doe
Advanced Link and Association Concepts
Link attributes for one-to-many association e.g. works-for and manages
Person
namesocial security no.address
Company
nameaddress
Works-for
salaryjob title
Manages worker
boss
performance rating
Advanced Link and Association Concepts
Folding link attributes It is possible to fold link attributes for one-to-one and one-to-
many associations into the class opposite the “one” site How is it possible and which one is preferred?
Person
namesocial security no.address
Company
nameaddress
Works-for
salaryjob title
Person
namesocial security no.addresssalaryjob title
Company
nameaddress
Works-for
Advanced Link and Association Concepts
Link attributes for ternary association
Pitcher Year
Team
winslosses
W LHarry Eisenstat Cleveland Indians 1939 6 7Harry Eisenstat Detroit Tigers 1939 2 2Willis Hudlin Cleveland Indians 1939 9 10Willis Hudlin Cleveland Indians 1940 2 1Willis Hudlin Washington Senators 1940 1 2Willis Hudlin St. Louis Browns 1940 0 1
Advanced Link and Association Concepts
Modeling an associations as a class Each link becomes one instance of the class It is useful when links can participate in associations with other
objects or when links are subject to operations
User WorkstationAuthorized on
Authorization
priorityprivileges
start session
Director
home directory
Advanced Link and Association Concepts
Ordering A special kind of constraint
Window ScreenVisible-on
{ordered}
Advanced Link and Association Concepts
Qualification A qualified association relates two object classes and a qualifier The qualifier distinguishes among the set of objects at the many
end of an association
Directory File
Directory Filefile name
Advanced Link and Association Concepts
Examples Ticker symbol of company in stock exchange
Company and office
Stockexchange
Company
ticker symbol
lists
Stockexchange
Company
ticker symbol
lists
Company Personofficeofficerorganization
Advanced Link and Association Concepts
Aggregation “Part-whole” or “a-part-of” relationship Used for components and assembly
• Existence of a part depends on existence of whole
Tightly coupled form of association extra semantics• Transitivity
• If A is part of B and B is part of C, then A is part of C
• Antisymmetric
• If A is part of B, then B is not part of A
• Propagation of properties
• e.g. location of a door handle is obtained from the door; door obtains its properties from the car, …
Document Paragraph Sentence
Generalization and Inheritance
Generalization The relationship between a class and one or more refined versio
n of it• superclass and subclass
“is-a” relationship Transitive
• ancestor and descendant
• An instance of a subclass is simultaneously an instance of all its ancestor classes
Equipment
namemanufacturerweightcost
Pump Tank
flow rate volume …
Generalization and Inheritance
Examples Fig. 3.23 and 3.24
Some guidelines Do not nest subclasses too deeply “An inheritance hierarchy that is two or three levels deep is certai
nly acceptable; ten levels deep is probably excessive; five or six levels may or may not proper”
Inheritance, generalization, and specialization Different viewpoints of the same relationship
A subclass is a special case of its superclass Don’t borrow a class using inheritance, when the new class is not
really a special case of the original class!
Remaining Parts
Grouping constructs Module and sheet
A sample object model Fig. 3.25: object model for window system
Practical tips …
Homework
HW7 Exercise 3.6 (p. 50)
HW8: extend E3.6a. Modify the class diagram in Figure E3.6 (p. 51) so as to handle u
nary minus and functions (e.g., sqrt(x) for calculating square root of x) with arbitrary number of arguments.
b. Prepare an instance diagram for the class diagram you made for the expression -(B + sqrt(B*B – 4*A*C))/(4*A*A).