Object Oriented Design

Download Report

Transcript Object Oriented Design



Week09

This week
o Review last class
o Class Diagrams
Sheridan
SYST30009 - Engineering Quality
Systems
2
Construct a class diagram from a narrative including
relationships and multiplicities.
 Identify and represent inheritance hierarchies in a
class diagram.
 Learn what is meant by a concrete and/or abstract
class.
 How to determine and note the constraints for
generalization / specialization relationships.
 Learn how to describe Whole-to-Part relationships on a
class diagram.
 How to draw all these relationships using System
Architect.

Sheridan
SYST30009 - Engineering Quality
Systems
3




Document the static
structure of the system
They define what classes
there are and how they are
related
The symbol on the right
defines the data and
behaviour encapsulated by a
class.
Objects “know things and
know how to do things!”
Sheridan
SYST30009 - Engineering Quality
Systems
4

Demo exercise
Sheridan
SYST30009 - Engineering Quality
Systems
5

From last class…
Sheridan
SYST30009 - Engineering Quality
Systems
6

We need to know what types of things the user works with
routinely.
o Many types
• Tangible
• Intangible
• Important to include information from all types of users
Sheridan
SYST30009 - Engineering Quality
Systems
7
Jacobson’s Three Types
Of Objects
•Entity
•Interface
•Control
Sheridan
SYST30009 - Engineering Quality
Systems
8


Attributes
Behavior (methods & operations)
o Real world
o Data world
Sheridan
SYST30009 - Engineering Quality
Systems
9
Class Diagram
Showing Two
Classes
Object Diagram
with Two Instances
Sheridan
SYST30009 - Engineering Quality
Systems
10
relationship among
object classes
 solid line connecting
classes
 association is named
i.e. drives
 where line connects to
class is called
“association role”

Sheridan
SYST30009 - Engineering Quality
Systems
11







shows number of objects in
an association
lower..upper bound
bounds are inclusive 2..5
0..1 = optional one
0..* = optional many
1..* = many
1 = exactly one
*
*
*
*
*
*
*
*
Sheridan
SYST30009 - Engineering Quality
Systems
12

Examples
Sheridan
SYST30009 - Engineering Quality
Systems
13

SLATE – Lesson 08 Class Diagram Exercises
Sheridan
SYST30009 - Engineering Quality
Systems
14
Sheridan
SYST30009 - Engineering Quality
Systems
15

Some instances of a class (subclass) may be grouped
together based on features not shared by the rest of the
class.
o Attributes
o Behavior
o Relationships

Key verb is “isakinda” (and inverse, “canbea”).
Sheridan
SYST30009 - Engineering Quality
Systems
16


A subclass is made up of
selected instances from
another class, the “Parent
class” or “superclass.”
A superclass includes all the
instances of the subclass,
plus possibly more as well.
Sheridan
SYST30009 - Engineering Quality
Systems
17
Each subclass then adds
attributes and behaviors
that it needs but the other

Inheritance is when a
subclass instance, in
addition to the attributes
and behavior it has by
virtue of being in the
subclass, also has all the
attributes and behavior that
instances of the superclass
have.
Sheridan
SYST30009 - Engineering Quality
Systems
one doesn’t.
18
The subclass
relationship actually is
a relationship in the
way we have used that
word.
 It requires a verb (one
in each direction).

o “isakinda”
o “canbea”
Sheridan
SYST30009 - Engineering Quality
Systems
19

To be considered truly O-O, a language, database, etc. must
support:
o Objects,
o Classes,
o Inheritance, and
o Polymorphism
Sheridan
SYST30009 - Engineering Quality
Systems
20

With subclasses, we can show more
detail about relationships on our
diagram.
For instance, in most companies,
only managers can hire and fire.
o In other words, only certain kindsa
employees can do certain tasks.
(only a baker can bake)
o

We are able to show that some
relationships affect only a subclass,
not every instance.
Sheridan
SYST30009 - Engineering Quality
Systems
21

SLATE- Inheritance Exercise
Sheridan
SYST30009 - Engineering Quality
Systems
22

generalization path
o solid line with hollow
arrowhead pointing from
subclass to superclass



indicate basis of
generalization
name the path for the
attribute being removed =
called the discriminator
discriminator shows which
property is abstracted by a
generalization relationship
Sheridan
SYST30009 - Engineering Quality
Systems
23


constraints on the subclasses
overlapping: descendent may
be descended from more than
one of the subclasses
o student can be both a
research and teaching
assistant

disjoint: descendent may not
be descended from more than
one of the subclasses
o patient can not be both out
and resident
Sheridan
SYST30009 - Engineering Quality
Systems
24

complete: all subclasses
are listed
o only have out and resident
patients

incomplete: all subclasses
are not listed
o more subclasses are
available
o can have casual, part-time
employees
Sheridan
SYST30009 - Engineering Quality
Systems
25
The UML provides ways to model two types of whole-topart associations – aggregation and composition.
Jerry Kotuba
SYST30009-Engineering Quality
Software
26

aggregate: In an aggregation, the class representing
the whole.
aggregation:
An association between classes representing a part-towhole relationship in which the parts and the whole
may exist independently and in which a single part may
be associated with more than one whole at the same
time.
Jerry Kotuba
SYST30009-Engineering Quality
Software
27

composite: In a composition, a class representing the
whole.
composition:
An association between classes representing a wholeto-part relationship in which the parts may belong to
only one whole at a time and the whole does not exist
without its parts.
Jerry Kotuba
SYST30009-Engineering Quality
Software
28
.
Jerry Kotuba
SYST30009-Engineering Quality
Software
29
.
Jerry Kotuba
SYST30009-Engineering Quality
Software
30
.
Jerry Kotuba
SYST30009-Engineering Quality
Software
31

There are three relationships that sometimes occur in
an object model:
o Assemblies of parts
o Members of groups
o Containers and their contents
You may find these useful for making your model a
better tool for understanding and communication.
 The model can always be built without these. They do
not really affect its use for system design, just for
talking to the users.

Jerry Kotuba
SYST30009-Engineering Quality
Software
32
Taking something apart into its components is
a technique we humans often use to
understand how something works.
 Often we find it improves our understanding to
model

o A product and its components
o A business consists of branches, departments, etc.
o A country consists of states, provinces, counties,
boroughs, shires, towns, villages, cities, etc.
Jerry Kotuba
SYST30009-Engineering Quality
Software
33
Container-Contents is a different and less common
relationship.
 In some situations we may find it helpful to view a
relationship as one of these, e.g.,

o Truck or Aircraft and the Products or Shipments that it carries
o An actual shipping container and the goods it holds
o A ship, bus or airplane and its passengers
o A building and the businesses it houses.
Jerry Kotuba
SYST30009-Engineering Quality
Software
34

The essential difference
between these
relationships is that:
o With Assemblies of parts,
if you take the
component away, the
assembly (whole)
probably won’t work any
more
o A Container, however, is still a
perfectly good Container, even
without its Contents
• The jar is still OK even
without the “hunny.”
o And the Contents are perfectly
OK without the Container
• (although the “hunny” might
get all over one’s paws!)
• Take a wheel off a car
• Take a hand off a clock
• Take a leg off a table.
Jerry Kotuba
SYST30009-Engineering Quality
Software
35


Collection-Member is also a
different and relatively
uncommon relationship.
Sometimes we meet an
actual collection:
o A library full of books
o An art gallery
o A stamp or jewelry collection
o A fleet of trucks, ships or

Other times it may help to
use this to describe:
o A place of worship, club or
regiment and its members
o An inventory of furniture or
equipment
o A herd, mob, flock, school or
skein of animals.
aircraft
Jerry Kotuba
SYST30009-Engineering Quality
Software
36


Draw the usual association link.
The “edit” the Association link and under the “aggregation”
column select “aggregate” for Basic or “composite” for
Composition
Jerry Kotuba
SYST30009-Engineering Quality
Software
37
Think about a book, which consists of a cover, table
of contents, chapters and an index. Chapters in turn
have pages, paragraphs and words. Show the
special case of association between classes
described here including the multiplicity.
Jerry Kotuba
SYST30009-Engineering Quality
Software
38

SLATE – ICE04 & ICE05 Vehicle Registration System
Sheridan
SYST30009 - Engineering Quality
Systems
39

State Diagrams
Sheridan
SYST30009 - Engineering Quality
Systems
40