22
More on Class Diagrams

Class Diagram

Embed Size (px)

DESCRIPTION

software engineering

Citation preview

Page 1: Class Diagram

More on Class Diagrams

Page 2: Class Diagram

Aggregation versus Composition Example

MovieTheater

BoxOffice

Movie

Are either of these aggregationor composition?

Page 3: Class Diagram

Aggregation versus Composition Example (cont.)

MovieTheater

BoxOffice

Movie

The BoxOffice will disappear ifthe Theater goes away!

But the Movies do not disappear.

How many of each class? (1, 1..*, etc)

Page 4: Class Diagram

Aggregation versus Composition Example (cont.)

MovieTheater

BoxOffice

Movie

1

1..*1..*

1

Page 5: Class Diagram

Constraints

A constraint is a condition that every implementation of the UML design must satisfy.

RedRocks

ConcertVenue

ConcertSchedule11

{only summer}

So RedRocks can only have a schedule during the summer season.

use curly braces

Page 6: Class Diagram

Constraints: Example

Section

Course

ClassSchedule0..*0..*

{if not cancelled}

use curly braces

Page 7: Class Diagram

Constraints: Another Example

Alphabet Letter{ordered}

So alphabet has to be ordered.

explain this?

Page 8: Class Diagram

Navigability: What About the Arrows?

Customer

Payment

Order

1..*

1

1..* 0..*

• The arrow gives the direction of traversal. • The Order class is invoking/instantiating the Payment class. • Or the Order class has a Payment.• “You can ask the Order about the Payment, but not vice-versa.”

No arrows is the same as anarrow in both directions.

Page 9: Class Diagram

Dependency

A dependency is a relation between two classes in which a change in one may force a change in the other.

Hotdog Mustard

Dashed line. This says: if you change the Mustard, you may also have to change the Hotdog class.

dependent class(that points to the class it uses or depends upon)

independent class

Page 10: Class Diagram

Dependency: Good Software Engineering?

They are an admission of defeat. Strongly coupled, less modular, not flexible,

less reliable (changes to code will cascade).

Consider redesign.

But, you should always show your dependencies!

They may be unavoidable.

Page 11: Class Diagram

Dependency Example

Use dashed line.

So both the Course and the ClassSchedule may have to change if the CourseOfferings change.

Section

Course

ClassSchedule0..*0..*

{if not cancelled}

CourseOfferings

Page 12: Class Diagram

Quick Review of Aggregation

Section

Course

ClassSchedule0..*0..*

{if not cancelled}

CourseOfferings

1

0..*

prerequisite

For each course there are 0 to many prereqs(which are also courses).

why not solid?

Page 13: Class Diagram

Object Diagrams: Motivation

Sometimes you need to explain how the objects will be implemented. Handy with recursive references…

Example:

Course

1

0..*

prerequisite

Needs clarification!

Page 14: Class Diagram

Object Diagrams

softwareEngineering: Course

oOProgramming: Course

java: Coursec++: Course

introToProgramming: Course

underline Objects!

C++ is an instance of a Course

instructor = “Bozo” Attributes are given actual values.

Page 15: Class Diagram

Object Constraints

oOProgramming: Course

java: Coursec++: Course

{if not c++}

Add constraints!

{if not java}

Was originally unclear which Prereq was required. Both?

Page 16: Class Diagram

Object Similar To Class Diagrams

Object Diagram allows multiple objects of same class.

Object Diagram shows actual values for attributes.

Otherwise, same as class diagram. Can have associations, constraints, etc.

Page 17: Class Diagram

Package Diagrams

Can also show how packages are related. Use rectangles with small tabs (a folder!).

java.lang sandwich

Page 18: Class Diagram

Can Put Classes In Package

This means that there is some association or dependencybetween classes in the package.

library.material

Book Magazine

NewspaperTextbook

Page 19: Class Diagram

Can Show Associations (but don’t have to)

library.material

Book Magazine

NewspaperTextbook

Page 20: Class Diagram

When Use a Package Diagram?

1. When you want to hide the inner workings of the package. (i.e., when don’t

want to show the inner class associations.)

2. When you want to make asociations between classes clearer. (just grouping

together)

Page 21: Class Diagram

Package Example

bank.bankLoan

road

driver country.state.city

vehicle

So we immediately seewhich packages depend on other packages.

suburb

note package in package

By the way, usually showassociations as dependenciesin a package diagram. But could show other associationsas long as you are clear.

Page 22: Class Diagram

Package Example 2

Section

Course

ClassSchedule0..*0..*

{if not cancelled}

1

1

CourseOfferings

1

0..*

prerequisite

university