Upload
ronics123
View
29
Download
2
Tags:
Embed Size (px)
DESCRIPTION
software engineering
Citation preview
More on Class Diagrams
Aggregation versus Composition Example
MovieTheater
BoxOffice
Movie
Are either of these aggregationor composition?
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)
Aggregation versus Composition Example (cont.)
MovieTheater
BoxOffice
Movie
1
1..*1..*
1
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
Constraints: Example
Section
Course
ClassSchedule0..*0..*
{if not cancelled}
use curly braces
Constraints: Another Example
Alphabet Letter{ordered}
So alphabet has to be ordered.
explain this?
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.
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
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
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
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?
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!
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.
Object Constraints
oOProgramming: Course
java: Coursec++: Course
{if not c++}
Add constraints!
{if not java}
Was originally unclear which Prereq was required. Both?
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
This means that there is some association or dependencybetween classes in the package.
library.material
Book Magazine
NewspaperTextbook
Can Show Associations (but don’t have to)
library.material
Book Magazine
NewspaperTextbook
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)
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.
Package Example 2
Section
Course
ClassSchedule0..*0..*
{if not cancelled}
1
1
CourseOfferings
1
0..*
prerequisite
university