Download More on Class Diagrams

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
More on Class Diagrams
Aggregation versus
Composition Example
MovieTheater
BoxOffice
Movie
Are either of these aggregation
or composition?
Aggregation versus
Composition Example (cont.)
MovieTheater
BoxOffice
Movie
The BoxOffice will disappear if
the Theater goes away!
But the Movies do not disappear.
How many of each class?
(1, 1..*, etc)
Aggregation versus
Composition Example (cont.)
MovieTheater
Movie
1..*
1
1
BoxOffice
1..*
Constraints
A constraint is a condition that every
implementation of the UML design must
satisfy.
use curly braces
RedRocks
ConcertVenue
{only summer}
1
1
ConcertSchedule
So RedRocks can only have a
schedule during the summer
season.
Constraints: Example
Section
{if not cancelled}
0..*
0..*
ClassSchedule
Course
use curly braces
Constraints: Another Example
explain this?
Alphabet
{ordered}
So alphabet has to be ordered.
Letter
Navigability: What About the
Arrows?
Customer
1..*
0..*
Order
1
No arrows is the same as an
arrow in both directions.
1..*
Payment
• 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.”
Dependency
A dependency is a relation between two
classes in which a change in one may
force a change in the other.
Hotdog
dependent class
(that points to the class it uses or depends upon)
Mustard
independent class
Dashed line. This says: if you change the Mustard,
you may also have to change the Hotdog class.
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.
Dependency Example
Section
{if not cancelled}
0..*
0..*
ClassSchedule
Use dashed line.
Course
CourseOfferings
So both the Course and the ClassSchedule
may have to change if the CourseOfferings change.
Quick Review of Aggregation
Section
{if not cancelled}
0..*
Course
0..*
ClassSchedule
CourseOfferings
0..*
1
why not solid?
prerequisite
For each course there are 0 to many prereqs
(which are also courses).
Object Diagrams: Motivation
Sometimes you need to explain how
the objects will be implemented. Handy
with recursive references…
Example:
Course
0..*
1
prerequisite
Needs clarification!
Object Diagrams
softwareEngineering: Course
instructor = “Bozo”
C++ is an instance of a Course
c++: Course
underline Objects!
Attributes are given
actual values.
oOProgramming: Course
java: Course
introToProgramming: Course
Object Constraints
Was originally unclear which Prereq was required. Both?
oOProgramming: Course
{if not java}
{if not c++}
c++: Course
java: Course
Add constraints!
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.
Package Diagrams
Can also show how packages are
related. Use rectangles with small tabs
(a folder!).
java.lang
sandwich
Can Put Classes In Package
library.material
Book
Textbook
Magazine
Newspaper
This means that there is some association or dependency
between classes in the package.
Can Show Associations
(but don’t have to)
library.material
Book
Textbook
Magazine
Newspaper
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.
together)
(just grouping
Package Example
vehicle
road
So we immediately see
which packages depend
on other packages.
By the way, usually show
associations as dependencies
in a package diagram. But
could show other associations
as long as you are clear.
country.state.city
driver
bank.bankLoan
suburb
note package in package
Package Example 2
Section
{if not cancelled}
0..*
0..*
ClassSchedule
1
1
Course
CourseOfferings
0..*
1
prerequisite
university