Title: UML Class Diagrams
1Object Oriented Analysis
2Outline
- Structural Modeling
- Class Diagrams and Object Diagrams
- Association
- Generalization ??? Classification
- Aggregation ??? Composition
- Models
3Structural Modeling
4What is structural modeling?
- Structural model
- ????????????????????????????????????? ???????????
(Class) ???????? ???????????????????????
(Relationship) ???????????
(Attribute) ??? ?????????? (operation)
5Structural Modeling Core Elements
6Structural Modeling Core Elements (contd)
¹ An extension mechanism useful for specifying
structural elements.
7Structural Modeling Core Relationships
8Structural Modeling Core Relationships (contd)
9Structural Diagrams
- ????????? Structural Diagrams
- static structural diagrams
- class diagram
- object diagram
- implementation diagrams
- component diagram
- deployment diagram
10Static Structural Diagrams
11Static Structural Diagrams
- ?????????????????????????????????? static
relationships - ????????? Static Structural Diagrams
- class diagram classifier view
- object instance diagram instance view
12Class Diagrams
- Class diagrams
- ????????????????? Class ??????????????????????
Class ??????????? logical view - ????????????? UML class diagrams ??????
- Class, ???????????? Class ?????????????? Class
- ????????? Multiplicity ??? navigation
- ??????? Role
- ??????????????? association, aggregation,
dependency, ??? inheritance
13Classes in UML
Class name
Person
Attributes
attribute name type
Operations
operation name(parameter type) result type
14UML Syntax for Attributes
- visibility name type
- id String
- visibility public (), protected (), private
(-) - ??????????????????? ??????????????????????
- name ???? string
- type ??????????????? ??????????????
15UML syntax for operations
- visibility name (parameter list)
return-type-expression - assignAgent (a Agent) Boolean
- visibility public (), protected (), private
(-) - ?????????????????????????????????????????
- name string
- parameter list arguments
- return-type-expression ??????????????? return
??????????????
16Attributes A Rule
- ???????? attributes ???????????? (simple)
- ???????????????? attributes ???????????????
(Object) - ??????????????? (class) ???? ?????????????????????
?????????????? association - ?????????????????????????????? 2 ???? ??????
foreign key attribute - ?????? association
17Object Instance Diagrams
- class diagram
- ???????? (name), ????????? (structure) ???
???????? (behaviour) ????????????????? (object) - object instance diagram
- ????????????????????????
- ?????????????????????? 2 diagram
??????????????????????????????????????????????????
???? relational database ?????????????????????????
?????
18Objects in UML
Object name
TimPerson
Tim Person
TaxIDNo23003 NameTimLim Income30000.00 Ta
xPaid FALSE
Attributes
attribute name type value
Same Operations for all instances of a class
calcTax() calcTaxBal()
19An Object Instance Diagram
20Classes and Objects
City
Name String default
Country String default
Population integer default
setName (s String deault)
setPopulation(p integer default)
ltltinstanceOfgtgt
ltltinstanceOfgtgt
ltltinstanceOfgtgt
New York City
Sydney City
London City
Name London
Name New York
Name Sydney
Country USA
Country Australia
Country UK
Population 2,324,320
Population 5,734,012
Population 3,536,000
21Class Diagrams
- Associations
- Generalization
- Generalization ??? Classification
- Aggregation
22Association
- ???????????? (Relationship) ??????? instances
??? classes
name direction
association name
Order
Customer
dateReceived
issued by
isPrepaid
name
1
number String
address
price Money
creditRating( )
dispatch( )
Customer may make several orders
Order comes from one customer
23Associations
- ??????????? 1 ???? ??????????????? associations
- Association
- ??????????? ER relationship ??????????????????????
????????????? ??????? ???????????? (links)
??????? ????????????????????????
24Naming associations
- ??????????? association
- ????????????????????????????????
- associated_with, has, is_related_to
- ?????????????????????? ????
- works_for, owns , issued by
- ??????????????????????? Association ????????????
???? ?????????????? diagram
25Associations on Class Diagrams
Owns
26Links
- ??????????????? ????????????????????? ??????
links - A link
- ???? instance ??? association
- ????????
- an association ????????????????? ????????????????
instance (links) ??? association ????????
???????????? ????????????????????????
???????????????????????? ????????????????????????
27Objects Links
YouPerson
MePerson
NameJane Address22 Holly Pl Telephone62312198
NameDennis Address41 High St Telephone62661734
Owns
Owns
Owns
OursCar
MineCar
ManufacturerSaab Model95 RegistrationYRT833
ManufacturerMazda Model626 RegistrationYYX391
28Association Multiplicity
- multiplicity
- ??????? ??????????????? instances (objects)
???????????? ????????????????????? instance
(object) ????????????????????
29Association Multiplicity
1
1..
Class
Class
exactly one
one or more
0..1
Class
Class
many (zero or more)
zero or one/at most one
2 ..4
Class
as specified
30Example of Multiplicities
Student
University
1
Heart
Body
2-3
Bicycle
Wheel
1..
1..
Account
Owner
31Associations, Objects Classes
- ?????? association ?????????? 2 ????? ????????
link ?????????? 0 ??? 1 link - ??????? 2 ????? ????????????????? 1 association
(Multiple Assoications) ??? association
?????????????????????????????????????????????
association - Multiple associations ???????????????????
???????? associations
32Roles
- role
- ??????? ????????????????????????????? association
???????????????????????????????????????
association - ??????????? role ??????????????????
(?????????????????? association ??????????? role - ????????????????????? Role ??? associations
???reflexive (Reflexive associations)
33Role names
- Role ???? ????????????????????? association
34Association Names Roles
- association ??????????????????????????????? role
????????????????????????????????????? - ???????????????? association ?????????????????????
?? role ??? - ?????????????????????????? association (??????
roles) ??????????????????????? association ???
35Role names
- ????????????????????? Role ??????????????????
link ???????????????????????????????
36A Reflexive Association
- association ???????????????????????
Person
Parent
Name Address Telephone
2
Role name
Child
37Ternary Associations
- A ternary association
- ???? assocation ????????????? 3 ????
- ????????????????????? ternary relationship ??ER
modelling ??????????????? ??? - ???????????????????????????????????
?????????????????????????????
38Ternary Associations
Vendor
Customer
Product
Sale
Ternary association
39Ternary Association Multiplicity
- multiplicity ??? ternary associations
- ???????????? binary ??? unary associations
- ??????? ??? many ???????????????????????
(participating)
40N-ary Associations
- ????????????? association ????????????????????????
??????????? - ??????????????????????? 2 ?????????? (???????
ternary) ???????? n-ary associations - ??? Associations ??????????????????? 0
???????????????
41Summary Basic notation for associations
Association name
mult1
mult2
Class A
Class B
role_A
role_B
contains
1
Order
Order Line
line items
42Association Classes
- Link ???????????? ????????????????????????????????
???? attribute ???????????? - attribute ???????????????? association ??????
association class ????????????????????????????????
???? ???????????????whenever it exists or has
meaning when the link itself exists (rather than
just the objects linked) - ??????????????????
many-to-many associations
43Association Classes
Student
Subject
Enrolment
ID Name Address Telephone
Code Name Credit
Result
Mark
Association class
44Association Classes
- association class ?????????????????? associations
????? ??????????????????????????????????
45Association Classes
Customer
Product
Purchase
Name Address Telephone
Number Name Price
Guarantee
0..1
Date Length Conditions
Claim
Association class
46Qualified Associations
- qualified association
- ??????? association ????????????????????
attribute ??????????? qualifier - ??????? qualified association ????????????????????
? weak entity type ?? ER
47Qualified Associations
48Qualified Association
Tournament
Prize
Year Position
0..1
49Qualified association
Organization
Company
Function
Person
- ABC Inc. President Roger Rabbit
- ABC Inc. Vice President Finances Joe Savemoney
- ABC Inc. Member of board John Walker
- ABC Inc. Member of board Susi Sanssouci
- ABC Inc. Member of board Karl Eichbaum
- XYZ Inc. President Donald Duck
50Class Diagrams Hints
- class ???????????????????????????????? diagrams
- Diagrams ????????????????????????
- ?????????????????????
- ????? associations ????????????
- ???? attributes ??? operations ???????????????????
? - ????????????????? diagram ???? ??????????
51Difference between attributes and associations
- Conceptual perspective
- ???????????????????
- Attributes ???????????? (single-valued)
- Specification/implementation perspective
- Attribute ??????? (Value) ????????????????
(References) - ???????? share ??????? attribute values ?????????
instances ??????????????????????? - Often Stores simple objects
- Numbers, Strings, Dates, Money objects
52Class diagrams (cont.)
- Associations
- Generalization
- Generalization ??? Classification
- Aggregation
53Generalization
- ???????????????????
- Generalization ?????? classes ????????????????????
????????????? (class Hierarchy) ???????
similarities ??? differences - ??????????????????????????????????????? classes
hierarchy ??? superclasses ?????????????????????
?????? subclasses - ???? kind-of relationship
54Inheritance and Polymorphism
- subclass ??????????????????? (inherits)?????????
attributes, operations ???associations ?????
superclass ????????? - ??????????????? ??? attribute ???? operation ???
superclass ?????????????????????????
subclass ????????? overrides
???????????????????? superclass -
?????????????? polymorphism
55Superclasses and Subclasses
- Superclass ????????? attributes, operations ???
associations ?????????? subclasses ???????????? - Subclasses ?? attributes, operations ???
associations ??????????????????
????????????????????????????????? attribute,
operation ???? relationship ???????????
superclass ????????????
56A Generalization Hierarchy
Geometric_Figure
Superclass
X_Position Y_Position
Ellipse
Circle
Rectangle
Major_Axis Minor_Axis
Radius
Width Height
Subclasses
57Single Multiple Inheritance
- generalizations ????????? class hierarchies
???????? subclass ??????? 1 superclass -
???????? single inheritance - ???????????????????? subclass ??????????????? 1
superclass - ???????? multiple inheritance
58Multiple Inheritance
Employee
GeneralStaff
ProfStaff
FullTime
PartTime
Subclass with two superclasses
Academic
59Multiple Inheritance
Vehicle
Furniture
Wheelchair
60Specialization
- Specialization
- ???????????????????????? generalization
???????????????? ???????????????????????????????? - Generalization ???????????????????????????? ???
(sub)classes - Specialization ?????????? ????????????????????????
? (super)classes ??????????? subclasses
61Class diagrams (cont.)
- Associations
- Generalization
- Generalization ??? Classification
- Aggregation
62Generalization and Classification ( is_a?)
- 1. Shep is a Border Collie.
- 2. A Border Collie is a Dog.
- 3. Dogs are Animals
- 4. A Border Collie is a Breed.
- 5. Dog is a Species
- 12 Shep is a Dog
- 123 Shep is a animal
- 14 Shep is a breed?????
- 25 A Border Collie is a Species?????
- Generalization is transitive (is kind of)
- Classification is not transitive (is instance of)
63Class diagrams (cont.)
- Associations
- Generalization
- Generalization ??? Classification
- Aggregation
64Aggregation
- Aggregation
- ?????????????????? association ???????????????????
?????????????? association ??????? - ?????????????? ?????????? ??????????????????
- ???? part-of relationship
65Notation for aggregation
Class A
Class A
Class B
????
Class C
Class C
Class B
66Example Aggregation
Book
1
1
Aggregation
1
0..1
1
Chapter
End
Front
1
1
1
1
1
0..1
0..1
Title
Preface
Appendix
Index
67Example Aggregation
Company
Unit
Department
Group
works for
Employee
68Aggregation
- ????? 2 ?????? Aggregation ??? Composition
- Aggregation
- ??????? ?????????? ??????????????????
- ???? Car ?? engine ???wheels ??????????????
- Composition
- ????????????????? ?????????????????????????
- ?????? message ??????????????????????????????????
??????????????????????????? - ??? delete ?????????????????????????
????????????????? delete ??????????
69Aggregation Composition
- ??????????????????? transitive
- ???????? A ???????????????? B ??? B
???????????????? C ???? A ???????????????? - ???? ?????????????????????????????? ?????
??????????????????????????? ????
????????????????????????????????? - ??????????????????? Anti-symmetric
- ???????? ?????????????????????????????????????????
?????????????????? - ???? ??????????????????????????????
????????????????????????????????????
70Aggregation and composition
Polygon
Aggregation
1
1
Composition
1
GraphicsBundle
3..
color texture
Point
71Association and Aggregation
- Question Association ???? Aggregation?
- Answer ???? Aggregation
- ??????????????????? part of
- Operation ????????????????????????????????????????
????????????????????????????????????????????
72Generalization and Aggregation
- Question Generalization ???? Aggregation ?
- Answer ???? Generalization
- ??????????????????? kind of
- ?????????????????? or
- Answer ???? Aggregation
- ??????????????????? part of
- ?????????????????? and
73Class Diagram - Example
- A zoo consists of a set of cages.
- Every cage is the home of at least 2 animals.
- Cages are located besides each other.
- Every cage has at most one left neighbor and at
most one right neighbor. - Animals can be reptiles, insects, and mammals.
- Mammals are elephants, monkeys, and tigers.
- Monkeys eat bananas.
- Tigers prefer meat.
74Class Diagram
RegistrationForm
Professor
name
tenureStatus
75Class Diagram Notation Summary
Association_name
1
signature
constraint
Role_name
Qualifier
discriminators
76Class Diagram Notation Summary (contd)
formal_arg
Parameterised ClassName
Instantiated ClassNameltactual_arggt
Instantiates
ClassName1
ClassName2
constraint
ClassName3
public protected - private null unspecified /
derived
ternary
77Models
78Three Perspectives
- Conceptual (OOA)
- ?????????????????????????????????
- ?????????? implementation
- Specification (OOD)
- ??????????????????????
- ????? Interfaces ??? software
- Implementation (OOP)
- ?????????? implementation (classes)
79Three Models
- Analysis Model
- Design Model
- Implementation Model