Class Diagram - PowerPoint PPT Presentation

About This Presentation
Title:

Class Diagram

Description:

8311302 Class Diagram Department of Informatics – PowerPoint PPT presentation

Number of Views:158
Avg rating:3.0/5.0
Slides: 77
Provided by: Jarun
Category:
Tags: cage | class | diagram | monkeys

less

Transcript and Presenter's Notes

Title: Class Diagram


1

Object Oriented Analysis And Design
  • 8311302 ??????????????????????????????
  • Class Diagram

Department of Informatics Faculty of Science and
Technology Phuket Rajabhat University 1/2553
2
Outline
  • Structural Modeling
  • Class Diagrams and Object Diagrams
  • Association
  • Generalization ??? Classification
  • Aggregation ??? Composition

3
Structural Modeling
4
What is structural modeling?
  • Structural model
  • ????????????????????????????????????? ???????????
    (Class) ???????? ???????????????????????
    (Relationship) ???????????
    (Attribute) ??? ?????????? (operation)

5
Structural Modeling Core Elements
6
Structural Modeling Core Elements (contd)
ยน An extension mechanism useful for specifying
structural elements.
7
Structural Modeling Core Relationships
8
Structural Modeling Core Relationships (contd)
9
Structural Diagrams
  • ????????? Structural Diagrams
  • static structural diagrams
  • class diagram
  • object diagram
  • implementation diagrams
  • component diagram
  • deployment diagram

10
Static Structural Diagrams
11
Static Structural Diagrams
  • ?????????????????????????????????? static
    relationships
  • ????????? Static Structural Diagrams
  • class diagram classifier view
  • object instance diagram instance view

12
Class Diagrams
  • Class diagrams
  • ????????????????? Class ??????????????????????
    Class ??????????? logical view
  • ????????????? UML class diagrams ??????
  • Class, ???????????? Class ?????????????? Class
  • ????????? Multiplicity ??? navigation
  • ??????? Role
  • ??????????????? association, aggregation,
    dependency, ??? inheritance

13
Classes in UML
  • ???????? 2 ??????

Class name
Person
Attributes
attribute name type
Operations
operation name(parameter type) result type
14
UML Syntax for Attributes
  • visibility name type
  • id String
  • visibility public (), protected (), private
    (-)
  • ??????????????????? ??????????????????????
  • name ???? string
  • type ??????????????? ??????????????

15
UML 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
    ??????????????

16
Attributes A Rule
  • ???????? attributes ???????????? (simple)
  • ???????????????? attributes ???????????????
    (Object)
  • ??????????????? (class) ???? ?????????????????????
    ?????????????? association
  • ?????????????????????????????? 2 ???? ??????
    foreign key attribute
  • ?????? association

17
Object Instance Diagrams
  • class diagram
  • ???????? (name), ????????? (structure) ???
    ???????? (behaviour) ????????????????? (object)
  • object instance diagram
  • ????????????????????????
  • ?????????????????????? 2 diagram
    ??????????????????????????????????????????????????
    ???? relational database ?????????????????????????
    ?????

18
Objects in UML
  • ???????? 2 ??????

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()
19
An Object Instance Diagram
20
Classes 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
21
Class Diagrams
  • Associations
  • Generalization
  • Generalization ??? Classification
  • Aggregation

22
Association
  • ???????????? (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
23
Associations
  • ??????????? 1 ???? ??????????????? associations
  • Association
  • ??????????? ER relationship ??????????????????????
    ????????????? ??????? ???????????? (links)
    ??????? ????????????????????????

24
Naming associations
  • ??????????? association
  • ????????????????????????????????
  • associated_with, has, is_related_to
  • ?????????????????????? ????
  • works_for, owns , issued by
  • ??????????????????????? Association ????????????
    ???? ?????????????? diagram

25
Associations on Class Diagrams
Owns
26
Links
  • ??????????????? ????????????????????? ??????
    links
  • A link
  • ???? instance ??? association
  • ????????
  • an association ????????????????? ????????????????
    instance (links) ??? association ????????
    ???????????? ????????????????????????
    ???????????????????????? ????????????????????????

27
Objects Links
YouPerson
MePerson
NameJane Address22 Holly Pl Telephone62312198
NameDennis Address41 High St Telephone62661734
Owns
Owns
Owns
OursCar
MineCar
ManufacturerSaab Model95 RegistrationYRT833
ManufacturerMazda Model626 RegistrationYYX391
28
Association Multiplicity
  • multiplicity
  • ??????? ??????????????? instances (objects)
    ???????????? ????????????????????? instance
    (object) ????????????????????

29
Association 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
30
Example of Multiplicities


Student
University
1
Heart
Body
2-3
Bicycle
Wheel

1..
1..
Account
Owner


31
Associations, Objects Classes
  • ?????? association ?????????? 2 ????? ????????
    link ?????????? 0 ??? 1 link
  • ??????? 2 ????? ????????????????? 1 association
    (Multiple Assoications) ??? association
    ?????????????????????????????????????????????
    association
  • Multiple associations ???????????????????
    ???????? associations

32
Roles
  • role
  • ??????? ????????????????????????????? association
    ???????????????????????????????????????
    association
  • ??????????? role ??????????????????
    (?????????????????? association ??????????? role
  • ????????????????????? Role ??? associations
    ???reflexive (Reflexive associations)

33
Role names
  • Role ???? ????????????????????? association

34
Association Names Roles
  • association ??????????????????????????????? role
    ?????????????????????????????????????
  • ???????????????? association ?????????????????????
    ?? role ???
  • ?????????????????????????? association (??????
    roles) ??????????????????????? association ???

35
Role names
  • ????????????????????? Role ??????????????????
    link ???????????????????????????????

36
A Reflexive Association
  • association ???????????????????????

Person
Parent
Name Address Telephone
2
Role name
Child

37
Ternary Associations
  • A ternary association
  • ???? assocation ????????????? 3 ????
  • ????????????????????? ternary relationship ??ER
    modelling ??????????????? ???
  • ???????????????????????????????????
    ?????????????????????????????

38
Ternary Associations
Vendor
Customer
Product
Sale
Ternary association
39
Ternary Association Multiplicity
  • multiplicity ??? ternary associations
  • ???????????? binary ??? unary associations
  • ??????? ??? many ???????????????????????
    (participating)

40
N-ary Associations
  • ????????????? association ????????????????????????
    ???????????
  • ??????????????????????? 2 ?????????? (???????
    ternary) ???????? n-ary associations
  • ??? Associations ??????????????????? 0
    ???????????????

41
Summary Basic notation for associations
Association name
mult1
mult2
Class A
Class B
role_A
role_B
  • ????????????

contains

1
Order
Order Line
line items
42
Association 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

43
Association Classes
Student
Subject
Enrolment
ID Name Address Telephone
Code Name Credit


Result
Mark
Association class
44
Association Classes
  • association class ?????????????????? associations
    ????? ??????????????????????????????????

45
Association Classes
Customer
Product
Purchase
Name Address Telephone
Number Name Price


Guarantee
0..1
Date Length Conditions
Claim

Association class
46
Qualified Associations
  • qualified association
  • ??????? association ????????????????????
    attribute ??????????? qualifier
  • ??????? qualified association ????????????????????
    ? weak entity type ?? ER

47
Qualified Associations
48
Qualified Association
Tournament
Prize
Year Position
0..1
49
Qualified 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

50
Class Diagrams Hints
  • class ???????????????????????????????? diagrams
  • Diagrams ????????????????????????
  • ?????????????????????
  • ????? associations ????????????
  • ???? attributes ??? operations ???????????????????
    ?
  • ????????????????? diagram ???? ??????????

51
Difference 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

52
Class diagrams (cont.)
  • Associations
  • Generalization
  • Generalization ??? Classification
  • Aggregation

53
Generalization
  • ???????????????????
  • Generalization ?????? classes ????????????????????
    ????????????? (class Hierarchy) ???????
    similarities ??? differences
  • ??????????????????????????????????????? classes
    hierarchy ??? superclasses ?????????????????????
    ?????? subclasses
  • ???? kind-of relationship

54
Inheritance and Polymorphism
  • subclass ??????????????????? (inherits)?????????
    attributes, operations ???associations ?????
    superclass ?????????
  • ??????????????? ??? attribute ???? operation ???
    superclass ?????????????????????????
    subclass ????????? overrides
    ???????????????????? superclass -
    ?????????????? polymorphism

55
Superclasses and Subclasses
  • Superclass ????????? attributes, operations ???
    associations ?????????? subclasses ????????????
  • Subclasses ?? attributes, operations ???
    associations ??????????????????
    ????????????????????????????????? attribute,
    operation ???? relationship ???????????
    superclass ????????????

56
A Generalization Hierarchy
Geometric_Figure
Superclass
X_Position Y_Position
Ellipse
Circle
Rectangle
Major_Axis Minor_Axis
Radius
Width Height
Subclasses
57
Single Multiple Inheritance
  • generalizations ????????? class hierarchies
    ???????? subclass ??????? 1 superclass -
    ???????? single inheritance
  • ???????????????????? subclass ??????????????? 1
    superclass - ???????? multiple inheritance

58
Multiple Inheritance
Employee
GeneralStaff
ProfStaff
FullTime
PartTime
Subclass with two superclasses
Academic
59
Multiple Inheritance
Vehicle
Furniture
Wheelchair
60
Specialization
  • Specialization
  • ???????????????????????? generalization
    ???????????????? ????????????????????????????????
  • Generalization ???????????????????????????? ???
    (sub)classes
  • Specialization ?????????? ????????????????????????
    ? (super)classes ??????????? subclasses

61
Class diagrams (cont.)
  • Associations
  • Generalization
  • Generalization ??? Classification
  • Aggregation

62
Generalization 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)

63
Class diagrams (cont.)
  • Associations
  • Generalization
  • Generalization ??? Classification
  • Aggregation

64
Aggregation
  • Aggregation
  • ?????????????????? association ???????????????????
    ?????????????? association ???????
  • ?????????????? ?????????? ??????????????????
  • ???? part-of relationship

65
Notation for aggregation
Class A
Class A
Class B
????
Class C
Class C
Class B
66
Example 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
67
Example Aggregation
Company
Unit

Department


Group
works for

Employee
68
Aggregation
  • ????? 2 ?????? Aggregation ??? Composition
  • Aggregation
  • ??????? ?????????? ??????????????????
  • ???? Car ?? engine ???wheels ??????????????
  • Composition
  • ????????????????? ?????????????????????????
  • ?????? message ??????????????????????????????????
    ???????????????????????????
  • ??? delete ?????????????????????????
    ????????????????? delete ??????????

69
Aggregation Composition
  • ??????????????????? transitive
  • ???????? A ???????????????? B ??? B
    ???????????????? C ???? A ????????????????
  • ???? ?????????????????????????????? ?????
    ??????????????????????????? ????
    ?????????????????????????????????
  • ??????????????????? Anti-symmetric
  • ???????? ?????????????????????????????????????????
    ??????????????????
  • ???? ??????????????????????????????
    ????????????????????????????????????

70
Aggregation and composition
Polygon
Aggregation
1
1
Composition
1
GraphicsBundle
3..
color texture
Point
71
Association and Aggregation
  • Question Association ???? Aggregation?
  • Answer ???? Aggregation
  • ??????????????????? part of
  • Operation ????????????????????????????????????????
    ????????????????????????????????????????????

72
Generalization and Aggregation
  • Question Generalization ???? Aggregation ?
  • Answer ???? Generalization
  • ??????????????????? kind of
  • ?????????????????? or
  • Answer ???? Aggregation
  • ??????????????????? part of
  • ?????????????????? and

73
Class 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.

74
Class Diagram
RegistrationForm
Professor
name
tenureStatus
75
Class Diagram Notation Summary
Association_name

1
signature
constraint
Role_name
Qualifier
discriminators
76
Class Diagram Notation Summary (contd)
formal_arg
Parameterised ClassName
Instantiated ClassNameltactual_arggt
Instantiates
ClassName1
ClassName2
constraint
ClassName3
public protected - private null unspecified /
derived
ternary
Write a Comment
User Comments (0)
About PowerShow.com