Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2
What
Are
Design
Pa6erns?
• Design
Pa\erns
are
…
formal
ways
of
documenRng
a
soluRon
to
a
design
problem
in
a
parRcular
field
of
experRse
Each
pa\ern
describes
a
problem
that
occurs
over
and
over
again
in
our
environment,
and
then
describes
the
core
of
the
soluRon
to
that
problem,
in
such
a
way
that
you
can
use
this
soluRon
a
million
Rmes
over,
without
ever
doing
it
the
same
way
twice.
—
Christopher
Alexander
The
usefulness
of
speaking
of
pa\erns
is
to
have
a
common
terminology
for
discussing
the
situaRons
designers
already
see
over
and
over.
Pa\erns are not the problem. The problem is when to apply them.
http://en.wikipedia.org/wiki/Design_pattern
3
Design
Pa6erns
In
OTM
• There
is
no
such
thing
as
a
“Design
Pa\ern”
in
OTM.
Is
there?
We
all
use
design
pa\erns
daily,
in
our
implementaRons
and
soluRon
designs.
Recognising
pa\erns
help
to
guide
design
decisions
and
know
what
is
feasible
and
what
is
not.
OTM
implementaRons
are
o<en
based
on
past
knowledge
and
experience.
Design
Pa\erns
help
to
“quanRfy”
and
“qualify”
knowledge
and
experiences
–
knowing
what
to
do
and
not
to
do.
4
Singleton
Pa6ern
Business
Problem
A
Forwarder
Cargo
Receipt
must
be
created
based
on
bookings.
Each
FCR
will
have
mulRple
booking’s
informaRon
such
as
weight,
volume,
piece
count
that
needs
to
be
rated
on
the
FCR.
FCRs
can
be
created
at
customer,
shipper,
voyage,
booking
line
or
container
level
OTM
Problem
We
need
to
trigger
one
single
workflow
for
mulRple
business
objects
for
the
purpose
of
applying
custom
logic
that
needs
to
consider
only
the
selected
specific
objects.
This
workflow
has
to
execute
only
once
for
this
group
of
selected
specific
objects.
5
Singleton
Pa6ern
In
so<ware
engineering,
the
singleton
pa\ern
is
a
design
pa\ern
that
restricts
the
instanRaRon
of
a
class
to
one
object.
This
is
useful
when
exactly
one
object
is
needed
to
coordinate
acRons
across
the
system.
The
term
comes
from
the
mathemaRcal
concept
of
a
singleton.
Wikipedia
h\p://en.wikipedia.org/wiki/Singleton_pa\ern
OTM
Problem
We
need
to
trigger
one
single
workflow
for
mulRple
business
objects
for
the
purpose
of
applying
custom
logic
that
needs
to
consider
only
the
selected
specific
objects.
This
workflow
has
to
execute
only
once
for
this
group
of
selected
specific
objects.
6
Singleton
Pa6ern
Other
business
Custom
PL/SQL
Saved query logic
7
Singleton
Pa6ern
SH_CUSTOM_SINGLETON
Data
Query
-‐
exec
PKG_SINGLETON.Run_Logic
Select
Primary_GID Custom
PL
/
SQL:
PKG_SINGLETON
From xxxx
Primary_GID
MW.S0001
-‐ FuncRon
to
return
1
GID
MW.S0002
…..
MW.S000X
Custom_Business_Logic
-‐ Procedure
to
execute
custom
logic
8
Singleton
Pa6ern
Advantages
Disadvantages
Simple
to
implement,
using
OOTB
Only
works
with
Data
Query
process
funcRonality
Applicable
to
any
business
object
that
can
PL/SQL
executed
business
logic
–
no
ability
be
triggered
through
Data
Query
to
trigger
subsequent
OTM
workflow
Easy
to
troubleshoot
and
debug
Main
logic
encapsulated
in
PL/SQL
9
Singleton
Pa6ern
• Approach
2:
UI
triggered
process
based
on
a
reuse
of
OTM
business
objects
• Implementa;on
• IdenRfy
an
OTM
business
object
that
OTM
has
the
ability
to
group
mulRple
objects
with:
• Job
(for
Orders
/
Shipments)
• Shipment
Group
(Shipments)
• Create
an
agent
that
will
be
raised
based
on
the
Create
event
of
the
business
object
• Create
a
PL/SQL
stored
procedure
to
• Get
the
Order
Release
IDs
/
Shipment
IDs
from
the
created
“proxy”
object
• Execute
your
custom
business
logic
based
on
the
IDs
based
on
the
created
“proxy”
object
• Don’t
forget
to
delete
the
original
object
as
part
of
the
cleanup!
10
Singleton
Pa6ern
Advantages
Disadvantages
Can
be
done
triggered
through
the
UI
Very
complex
logic
to
cleanup
the
“used”
OTM
business
object
*Limited
to
OTM
objects
(Job,
Shipment
Group)
11
Recursion
Pa6ern
Business
Problem
Assign
a
set
of
unique
Consignment
Note
numbers
to
each
equipment
in
a
shipment.
OTM
Problem
Assign
a
set
of
unique
Consignment
Note
numbers
to
each
equipment
group
in
a
shipment
and:
1) For
each
equipment
group
in
the
shipment,
all
the
equipments
in
the
equipment
group
must
have
a
modulo
11
check
digit.
The
first
equipment
has
a
unique
prefix.
2) All
equipments
must
be
assigned
connote
numbers
before
the
shipment
is
sent
out
to
the
Carrier
3) If
there
is
any
equipment
group
not
assigned
a
connote
number,
the
operaRons
must
be
alerted
and
the
tender
to
the
carrier
stopped.
4) Needs
to
use
OTM’s
BN
Number
Generator
because
of
the
need
to
maintain
Carrier
specific
connote
ranges.
5) All
this
must
be
done
when
the
shipment
is
built.
6) And
dinner
for
5
must
be
ready
by
6
pm
everyday
:o
12
Recursion
Pa6ern
13
Recursion
Pa6ern
Option 1
14
Recursion
Pa6ern
Option 2
15
Recursion
Pa6ern
Recursion
is
the
process
of
repeaRng
items
in
a
self-‐similar
way.
The
most
common
applicaRon
of
recursion
is
in
mathemaRcs
and
computer
science,
in
which
it
refers
to
a
method
of
defining
funcRons
in
which
the
funcRon
being
defined
is
applied
within
its
own
definiRon.
Specifically,
this
defines
an
infinite
number
of
instances
(funcRon
values),
using
a
finite
expression
that
for
some
instances
may
refer
to
other
instances,
but
in
such
a
way
that
no
loop
or
infinite
chain
of
references
can
occur.
Wikipedia
h\p://en.wikipedia.org/wiki/Recursion
Recursion is everywhere! J
16
Recursion
Pa6ern
Triggering Agent
17
Recursion
Pa6ern
• It
depends
….
Agent
must
have
only
1
event
triggering
it
Assign
Connote
Business
logic
must
apply
only
on
data
Event:
ASSIGN_CONNOTE
that
does
not
cause
deadlock
(e.g.
not
the
same
Equipment
Group
ID).
IF
NOT
ALL
Connotes
Assigned
THEN
Execute
business
logic
…
Generate
Connote
….
PL
/
SQL
….
Must
use
Create
New
Process
so
as
not
to
cause
the
agent
thread
from
causing
too
many
waits.
Raise
ASSIGN_CONNOTE,
Create
New
Process
ELSE
There
must
not
be
any
agent
acRons
STOP
and
END
beyond
this
point
–
so
as
to
prevent
any
END
IF
accidental
deadlocks
because
other
agents
could
be
updaRng
the
same
object
18
Recursion
Pa6ern
• Planned
and
assigned
9000
connotes
to
4,584
shipments
(average
of
2
equipment
groups)
in
19
mins
–
not
too
bad
19
Other
Design
Pa6erns?
• Pa\erns
are
based
on
your
experience
and
creaRvity
–
document
&
capture
them
as
part
of
your
toolkit
• Learn
to
work
within
the
constraints
of
the
available
tools
and
funcRonaliRes
• Important
points
to
remember
• Agents
are
mulR-‐threaded
and
hence
cannot
to
control
sequence
of
execuRon
• Be
aware
of
race-‐condiRons
&
deadlocks
• Avoid
using
semaphores
/
locks
to
control
agent
execuRon
–
work
with
OTM;
not
against
J
• Always
check
to
ensure
performance
(get
it
right
first
then
worry
about
performance)
• OTM
is
your
friend
…..
20
Thank
you
ian.lo@mavenwire.com