Escolar Documentos
Profissional Documentos
Cultura Documentos
UML has several dierent diagrams: each show the rela)onship among dierent sets of en))es, depending upon the purpose of the diagram. Use Case (Analysis Phase) involve en))es interac)ng with the system Interac)on Diagrams (Looking at Objects Interac)ons) Shows how specic objects interact with each other Class Diagrams (Design Phase) detail the rela)onships between classes State Diagrams (Looking at Objects Behaviors) Detail the dierent states an object may be in as well as the transi)ons between states 2
Class
Diagram
Describes
classes
and
shows
the
rela)onships
between
them.
When
one
class
is
a
kind
of
another
class;
the
is-a
rela)onship
When
there
are
associa)ons
between
two
classes
One
class
contains
another
class:
the
has-a
rela)onship
-
Composi)on:
the
contained
item
is
part
of
the
containing
item
(an
engine
in
a
car)
-
Aggrega)on:
the
contained
item
is
part
of
a
collec)on
of
items(airplanes
in
an
airport)
One
class
uses
another
class:
the
uses-a
rela)onship
One
class
creates
another
class
3
Class
Diagram
A
rectangle
represents
a
class.
Three
aspects
to
the
rectangle/class
are:
The
name
of
the
class
The
data
members
of
the
class
The
methods
of
the
class
Example
Scope identifier (Public (+), private (-), protected (#). The name of the attribute, colon, the data type of the attribute
4
Design
Pa3erns
When
we
study
so\ware
design
pa3erns,
we
will
describe
them
using
the
following
structure:
Name:
All
pa3erns
will
have
a
unique
name
that
iden)es
them.
Intent:
The
purpose
of
the
pa3ern.
Problem:
The
problem
that
the
pa3ern
is
trying
to
solve.
Solu0on:
How
the
pa3ern
provides
a
solu)on
to
the
problem
in
the
context
in
which
it
shows
up.
Par0cipants
and
collaborators:
The
en))es
involved
in
the
pa3ern.
Consequences:
The
consequences
of
using
the
pa3ern.
Implementa0on:
How
the
pa3ern
is
implemented.
Generic
Structure:
A
standard
diagram
that
shows
a
typical
structure
for
the
pa3ern
10
Scope: domain over which a pattern applies Purpose: reflects what a pattern does
11
Adapter
Pa3ern
This
is
a
problem
that
cries
out
for
polymorphism.
We
need
to
create
a
shape
class
and
have
the
concrete
classes
of
point,
line,
and
square
derive
from
shape
as
in
the
following
gure:
12
Adapter
Pa3ern
We
dene
a
series
of
behaviors
(methods)
that
all
Shapes
will
have
in
common
in
the
Shape
class
and
then
override
their
behavior
in
the
concrete
classes
of
Point,
Line,
and
Square.
A
Shape
must
be
able
to:
Set
its
loca)on
Get
its
Loca)on
Display
itself
Fill
itself
Set
its
color
Undisplay
itself
A
more
detailed
UML
specica)on:
13
Example
What
if
I
need
to
add
a
class
for
circle,
and
I
already
have
an
XXCircle
class
that
handles
all
the
func)onali)es
requirde
but
with
a
dierent
interface:
displayIt();
llIt();
undisplayIt();
Should
I
rewrite
class?
14
Example
Create
a
Circle
object
that
encapsulates
XXCircle
by
making
an
XXCircle
object
an
a3ribute
of
the
Circle
class.
15
Sample
Code
Some
sample
code
to
help
you
see
how
the
adapter
works:
Class
Circle
extends
Shape
{
private
XXCircle
myXXCircle;
public
Circle
()
{
myXXCircle
=
new
XXCircle();
}
void
public
display()
{
myXXCircle.displayIt();
}
}
16
Adapter
Pa3ern
Intent:
Match
an
exis)ng
object
beyond
your
control
to
a
par)cular
interface
Problem:
A
system
has
the
right
data
and
behavior,
but
the
wrong
interface.
Solu0on:
Provides
a
wrapper
with
the
desired
interface.
P
&
C:
Adapters
Target
(the
class
it
derives
from).
Allows
the
Client
to
use
the
Adaptee
as
if
it
were
a
type
of
Target.
Consequences:
Allows
for
preexis)ng
objects
to
t
into
new
class
structures.
Implementa0on:
Contain
the
exis)ng
class
in
another
class.
Have
the
containing
class
match
the
required
interface
and
call
the
methods
of
the
contained
class.
17
18
Provide a unied interface to a set of interfaces in a subsystem. Faade denes a higher level interface that makes a subsystem easier to use.
Its basically saying that we need a simpler way to access a complex system.
19
Facade
Pa3ern
Typically
the
faade
works
with
a
client
wan)ng
to
access
a
subset
of
the
overall
subsystem.
20
Facade
Pa3ern
Intent:
You
want
to
simplify
how
to
use
an
exis)ng
system.
You
need
to
dene
your
own
interface.
Problem:
You
need
to
use
only
a
subset
of
a
complex
system.
Solu0on:
Create
a
new
interface
for
the
client
to
use.
Par0cipants
and
Collaborators:
Simplied
interface
for
client
Consequences:
Simplies
the
us
of
a
required
subsystem,
but
reduces
op)ons.
Implementa0on:
Dene
a
new
class
(or
classes)
that
has
the
required
interface
and
uses
the
exis)ng
system.
21
Example
Complexity
can
be
greatly
reduced
for
the
applica)on
that
accesses
a
faade
instead
of
a
or
many
subsystems:
22
23