Uml Class Diagram 3 Relationships

  • Uploaded by: thanhluantink30c
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Uml Class Diagram 3 Relationships as PDF for free.

More details

  • Words: 1,284
  • Pages: 35
CONCEPTUAL DESIGN: UML CLASS DIAGRAM RELATIONSHIPS

1

A Simplified Object-Oriented Systems Analysis & Conceptual Design Methodology Activities 1.Identify the information system’s purpose 2.Identify the information system’s actors and features 3.Identify Use Cases and create a Use Case Diagram 4.Identify Objects and their Classes and create a Class Diagram 5.Create Interaction/Scenario Diagrams 6.Create Detail Logic for Operations 7.Repeat activities 1-6 as required to refine the “blueprints”

2

Objects •Objects have three responsibilities:

✔What they know about themselves – (e.g., Attributes) ✔ What they do – (e.g., Operations) ✔What they know about other objects – (e.g., Relationships)

3

Defining Class A CLASS is a template (specification, blueprint) for a collection of objects that share a common set of attributes and operations.

Class

HealthClubMember attributes operations

Objects

4

•Relationships A RELATIONSHIP is what a class or an object knows about another class or object.

Four Types

✔Generalization (Class-to-Class) (Superclass/Subclass) •Inheritance •Ex: Person - FacultyPerson, StudentPerson, Staff... •Ex: ModesOfTravel - Airplane, Train, Auto, Cycle, Boat...

✔[Object] Associations •FacultyInformation - CourseInformation •StudentInformation - CourseInformation

✔[Object] Aggregations & Composition (Whole-Part) •Assembly - Parts •Group - Members •Container - Contents 5

• Relationships Exist to: 1) show relationships 2) enforce integrity 3) help produce results

In this example: UniversityCourse

1

StudentInformation

0,m 1

StudentInCourse 0,m

•Removal of a University Course should also remove Students that are in the Course but not Student Information. • •Removal of a Student should also remove the Courses that the Student is in but not the University Course. • •Removal of a Student in a Course should not affect either University Course or Student Information. 6

UML Class Diagram Notation

1 of 2

Class

attributes

{

operations

{

Member memberNumber firstName lastName telephone address city etc... checkOutVideo checkInVideo buyItem etc...

Expanded view of a Class into its three sections: Top: Class Name Middle: attributes Bottom: operations

7

UML Class Diagram Notation

2 of 2

Class Generalization Relationship

Object Aggregation Association

Object Association n

n

Object Composition Association 1

1..* 0..*

0..*

Will always be “1” 8

Class Diagram Relationships ■

Class • Generalization



Object • Association • Aggregation • Composition

9

Generalization (Class-to-Class) (superclass – subclass; supertype – subtype) ■









■ ■

A Generalization follows a “is a” or “is a kind of” heuristic from a specialization class to the generalization class. (e.g., student “is a” person, video “is a kind of” inventory). Common attributes, operations and relationships are located in the generalization class and are inherited by the specialization classes Unique attributes, operations and relationships are located in the specialization classes. Inherited attributes and operations may be overridden or enhanced in the specialization class depending on programming language support. Inherited operations in the specialization classes may be polymorphic. Only use when objects do NOT “transmute” (add, copy, delete) Multiple inheritance is allowed in the UML but can complicate the class model’s understanding and implementation (e.g., C++ supports but Java and Smalltalk do not).

10

Generalization Example

operations

Others: •Transactions •Things •Places •Etc...

Faculty

Student

Staff

attributes

attributes

attributes

attributes

operations

operations

operations

operations

<>

Role attributes

Visitor

Note: <> = no objects 11

Poor Generalization Example

(violates the “is a” or “is a kind of” heuristic)

Person attributes operations

Leg

Head

attributes

attributes

attributes

operations

operations

operations

Arm

12

Generalization Inheritance Generalization

Common

a1 a2 a3 o1 o2 o3

One-Way Inheritance from the Generalization to the Specialization

Specialization

Unique

a4 a5 a6 o4 o5 o6 (a = attribute; o = operation)

Generalization

a1 a2 a3 o1 o2 o3

Specialization

a1 a2 a3 a4 a5 a6 o1 o2 o3 o4 o5 o6 13

Generalization - Multiple Inheritance Generalization2

Generalization1 a1 a2 a3

a2 a4 a5

o3 o4 o5

o1 o2 o3

Specialization a6 a7 a8 inherited attributes

o1 o2 (which one?) o3 o4 o5

o6 o7 o8

a1 a2 (which one?) a3 a4 a5

inherited operations

14

UML Generalization Notation Note Useful text

Supertype discriminator

Subtype 1

Subtype 2

Note: Supertype = Superclass; Subtype = Subclass

15

Generalization - Multiple Classification Discriminator Female

role <>

Male

Doctor

Gender Person {complete} patient

Nurse

Physicaltherapist

#1 Patient #2

#3 16

Rational Rose Class Diagram Example 17

Associations ■Relationships

of classes ■Conceptual:

between instances (objects)

•associations can have two roles (bidirectional): –source --> target –target --> source •roles have multiplicity (e.g., cardinality, constraints) •To restrict navigation to one direction only, an arrowhead is used to indicate the navigation direction ■No

inheritance as in generalizations 18

Object Association Relationship Patterns b) Object Aggregation Associations x

Class A attributes operations x

x Part1 attributes operations

x Class B attributes operations

Class A attributes operations

x x

Whole attributes operations

Class B attributes operations

a) Object Associations

c) Object Composition Associations

x

Part1 attributes operations

x

x Part2 attributes operations

PartN attributes operations

Whole attributes operations

(y may not be “1”) 1 y

x

1 y Part2 attributes operations

1 y PartN attributes operations

19

Associations role B Class A

Class B

role A

Example:

Company

Employee Employer

Person

20

Multiplicities 1 0..* 0..1 m..n

Class

exactly one

Class

many (zero or more)

Class

optional (zero or one)

Class

numerically specified

Example: Course

0..* 1

CourseOfferin g 21

Aggregation & Composition •Aggregation (shared aggregation): •is a specialized form of ASSOCIATION in which a whole is related to its part(s). •is known as a “part of” or containment relationship and follows the “has a” heuristic •three ways to think about aggregations: •whole-parts •container-contents •group-members •Composition (composite aggregation): •is a stronger version of AGGREGATION •the “part(s)” may belong to only ONE whole •the part(s) are usually expected to “live” and “die” with the whole (“cascading delete”) •Aggregation vs. Composition vs. Association??? 22

Aggregation Faculty

(team-teaching is possible)

1..*

Composition SalesOrder

1 0..*

1..*

CourseTeaching

SalesOrderLineItem

(another: assembly --> part)

(another: hand --> finger)

23

Composition ✔Composition is often used in place of

Generalization (inheritance) to avoid “transmuting” (adding, copying, and deleting of objects) Person {abstract}

Person

1 0..1

Faculty

Student

FacultyRole

1 0..1

StudentRole FacultyStudent Note: Attributes may need to be considered to more-fully understand

24

Association, Aggregation and Composition Template/Pattern Whole

Example Whole

w 1 w 2 w 3 w 4

0..*

0..* Part

Part

p p 4 p p 2 3 1

p 5

p 6

(association, aggregation & composition look the same) 25

Multiplicity Example #1 Whole

1

5

2

Part1

•One Whole is associated with 5 Part1 •One Part1 is associated with 1 Whole

W

P P P P P

P

3 PartN

•One Whole is associated with 2 PartN •One PartN is associated with 3 Whole

P P

W W

W P

W W

26

Multiplicity Example #2 Class1

min.

max.

1

1..n

2..5

0..*

Class2

1..n C1

C2 C2 C2 C2 C2

etc...

1 C2

C1

Class3

* C1

C3 C3 C3 C3 C3

2..5 C3

C1 C1 C1 C1 C1

etc... 27

Multiplicity Example #3

FacultyInformation

1

0..*

1

StudentInformation

1

1

0..*

1..*

0..*

CommitteeAssign

DegreeHeld

0..* CourseTeach

CourseCompleted

0..* ClubMember

28

“many-to-many” multiplicity StudentInformation attributes operations

CourseInformation

0..*

attributes operations

0..*

Becomes either

StudentInformation

CourseInformation

StudentInformation

attributes operations

attributes operations

attributes operations

0..*

CourseInformation

0..*

attributes operations

1

1

0..*

0..* StudentCourseInformation SemesterTaken GradeEarned

operations

Attributes that represent the “union” of the two classes are located in this “association” class.

StudentCourseInformation SemesterTaken GradeEarned

operations

29

Reflexive Association Relationships Objects within the same class have a relationship with each other.

Course 0..*

is pre-requisite for

0..*

has pre-requisite of

30

Video Store – UML Class Diagram 1 1 Inventory RentalItem

SaleItem

Video

Game

Transaction

0..* 1

ConcessionItem

Employee

SaleTransaction 1

0..*

0..*

RentalTransaction 0..* 1 0..1 1 Member

1..* 1..* SaleRentalLineItem

0..* 1

VCR

StoreLocation

Suplier 1 0..* PurchaseOrder 1

1..* PurchaseOrderLineItem

0..* 31

32

33

34

QUITTING

TIME

35

Related Documents

Uml - Class Diagram
August 2019 30
Uml Class Diagram
June 2020 22
Uml Diagram
June 2020 8
Class Diagram
June 2020 10
Class Diagram
May 2020 12

More Documents from ""

Uml Use Case Modeling
June 2020 22
Uml Activitydiagram
June 2020 13
Uml Intro H1
June 2020 16
Uml Class Diagram
June 2020 22