Architectural Design Patterns 2.
Components & Connectors and
Component Architecture Patterns and
UML 2.0 Ports
(BPD. Chapter 4. p. 184-201)
Architecture & Design of
Embedded Real-Time
Slide 2
Agenda
• Component Notation
• Component-based architecture Pattern
• Component & Connectors
• ROOM Pattern
UML Component Notation (1)
MyInterface
Provided
interface
An interface:
defines operation signatures
(name, parameters and return type)
«component»
Component
Required
interface
Slide 4
UML Component Notation (2)
OrderEntry
«component»
Order
Person
«component»
Order
«Interface»
Person
+create()
+findByName()
+getDeatils()
«Interface»
OrderEntry
+create()
+validateDetails()
+addOrderline()
«use»
Detailed view
Compact view
Assembly
Connector
Slide 6
Component-Based Architecture
A component in UML is a run-time artifact
that forms the basic replaceable unit of
software
Component examples: static libraries,
dynamic link libraries (DLLs), OCX and
Slide 8
Slide 10
Component & Connectors
• Existing research has focused on
– Component structure
– Component Interfaces
– Component functionality
• More focus needed on component
interactions embodied in the notation of
Connectors
• Connector definition:
– ”Connectors mediates interactions among
components, that is, they establish the
rules that govern component interaction
and specify any auxiliary mechanism
required”
• Connectors should be
first-class
modeling constructs
• Ref. Article:
Slide 12
ROOM Pattern
ROOM (Real-Time Object-Oriented
Methodology).
The ROOM Pattern is appropriate when
the interaction of some large-scale
objects is complex and requires special
Slide 14
ROOM Ports (~UML Ports)
Master:
Comm Object
Slave:
Comm Object
iSender
iReceiver
Slide 16
UML 2.0 Ports
Ports
“The Ports subpackage provides mechanisms for
isolating a classifier from its environment
. This is
achieved by providing a point for conducting interactions
between the internals of the classifier and its
environment. This interaction point is referred to as a
“port.”
Multiple ports can be defined for a classifier, enabling
different interactions to be distinguished based on the
port through which they occur.
By decoupling the internals of the classifier from its
environment,
ports allow a classifier to be defined
independently of its environment
, making that classifier
reusable in any environment that conforms to the
Slide 18
New UML 2.0 Concepts for Classes
A
port
groups interfaces belonging to a particular
stakeholder. A port can have as well
provided
as
required interfaces
.
Example with Internal Structure
Black Box
View
White Box
View
Structured
Class
Slide 20
Example: Home Alarm System – version 1
h omeow ner h omeow ner intruder intruderhome alarm
vi a remo te d ete ct intrusio nso ccupation simu la tio n
<<e xte nd >>
code entry
<<inclu de>>
arming and di sarming
sound alarm
«extend»
via keypad
<<in clud e>> <<e xte nd >>
<<inclu de>>
«extend»
Slide 22
Home Alarm System – version 1
Hardwa rePkg
IHardwa re
«Int erface »1
1
itsAlarmController
th eHardware
AlarmPkg
Alar mContro ller
« Facad e»
1
1
itsAlarmController
th eHardware
Without
Using
ports
Slide 24
AlarmController – a Composite Class
Alarm Controller
«Facade» theRedLed:Led 1 theGreenLed:Led 1 t heKey pad:Keypad 1 1 t heLightController:LightControllerIHardware
«Interf ace»setLight(aLight:tLights ,state:tOnOff):void
onArm():void
onDisarm():void
onKeyOff():void
onKeyOn():void
onKey(n:int):void
onMovement():void
onDoor():void
setLed(ident:tLed,s tate:tOnOff):void
setSiren(state:tOnO ff):void
1
1
itsAlarmController
theHardware
AlarmController State Diagram
off
/init();
armed
exiting
evTemporise
active
detecting
tm (EXIT_TIME)
silence
tm(SILENCE_TIME)
entering
evDoor
intrusion
evMovement
evMovement
tm(ENTRY_TIME)
tm(ALARM _TIME)
tm(SILENCE_TIME)
evDoor
evMovement
evMovement
tm(ENTRY_TIME)
tm(ALARM _TIME)
evArm
evDisarm
tm (EXIT_TIME)
tm(SILENCE_TIME)
evDoor
evMovement
evMovement
tm(ENTRY_TIME)
tm(ALARM _TIME)
Slide 26
AlarmController – Public Operations
AlarmController
«Facade»configure(aHardware:IHardware*):void
AlarmController()
flashGreenLed():void
onArm():void
onDisarm():void
onDoor():void
onKey(n:int):void
onKeyOff():void
onKeyOn():void
onMovement():void
evArm():void
evMovement():void
evDoor():void
evTemporise():void
evDisarm():void
HardwarePkg::IHardware
«Interface»setLight(aLight:tLights,state:t...
onArm():void
onDisarm():void
onKeyOff():void
onKeyOn():void
onKey(n:int):void
onMovement():void
onDoor():void
setLed(ident:tLed,state:tOnO...
setSiren(state:tOnOff):void
1
1
theHardware
itsAlarmController
Possible Hardware Implementations
TestPkg AlarmHw 68kPkg Hw AlarmHw 486Pkg Hw Irq Hw Poll IHardw are «Interf ace» onArm( ):void onDisarm():void onKeyOff() :void onKeyOn():void onKey( n:int):void onMovement():void onDoor ():void setLed(ident:tLed,state:tO... setSiren(state:tOnOff):void SimulatedHw Pkg guiDlgSlide 28
Home Alarm – version 2 with Ports
• Ports are a new UML2.x modeling concept
that allows strong encapsulation of classes
from the environment.
• In this case, the Hardware and Alarm
Controller are decoupled by specifying ports
as their boundary interaction points.
Package Diagram
PORT:
hwObserver
With 3
provided
interface
PORT:
hwCtrl
With 3
required
interface
HardwarePkg Simu la te dHwPkg gui Dlg HwTe stPkg H w AbstractHW AbsHardwareILedCt rl,ILight Ct rl,ISi ren Ctrl IK ey Li ste ne r,I Mo v emen tList ener, IDoorLi ste ne r
ctrl
AlarmPkg
AlarmCo ntro ller
«F acade»
IDoorListener,IKey Listener,IMov ementListener
hwOb serve r
ILedCtrl,ILightCtrl,ISirenCtrl
hwCtrl
Slide 30
Home Alarm – version 2 with Ports
Al arm Control ler
«F aca de»
th eGree nL ed :Le d
1
ILedCtrl
hw
th eL igh tController:LightC on trol ler
1
ILightC trlhw
theKeypad:Keyp ad
1theRedLed:Le d
1
IL edC trlhw
theSiren :Siren Co ntroll er
1
IS iren Ctrl
hw
IDoorListener,IKey Listener,IMov ementListen er
hw Obse rve r
IL edC trl,IL igh tCtr l,ISi renC trl
hwC trl
PORT:
hwObserver
PORT:
Classes: KeyPad, SirenController, Led
Keypad
newCode:int
count:int
oldCode:int
Keypad()
isCodeCorrect():OMBoolean
isCodeEntered():OMBoolean
changeCode():void
evKeyOff():void
evKey():void
evKeyOn():void
SirenController
setSirenOn():void
setSirenOff():void
ISirenCtrl
hw
Led
Led()
evToggle():void
evFlash():void
evOn():void
evOff():void
ILedCtrl
hw
Slide 32
KeyPad – State Diagram
activeidle
[IS_IN(cor rect)]/
itsController- >GEN(evTemporise); evKeyOn
evKeyOff [IS_IN(cor rect)]/ itsController- >GEN(evDisarm) ; reprogramming w aitNew Code evKeyOn[IS_IN(different) ]/ changeCode(); w aitOldCode [else] [IS_IN(c orrect)] evKey On tm(10000) evKeyOff [IS_IN(notEntered) ] [IS_IN(c orrect)] evKey On armingDisarmingReprogr amming [else] evKeyOn[IS_IN(different) ]/ changeCode(); [IS_IN(cor rect)]/ itsController- >GEN(evTemporise); evKeyOn
evKeyOff [IS_IN(cor rect)]/ itsController- >GEN(evDisarm) ; tm(10000) evKeyOff [IS_IN(notEntered) ] [IS_IN(c orrect)] evKey On currentCode correct dif ferent notEntered tm(3000) tm(3000) [is CodeCorrect()] [else] tm(3000) tm(3000) enteringCode ev KeyOff tm(5000) evKey/
new Code = params->n; count=1;
evKey/
new Code = (10 * new Code ) + par ams ->n; c ount++; [isCodeEnter ed() ] codeEntry [is CodeCorrect()] [else] tm(3000) tm(3000) ev KeyOff tm(5000) evKey/
new Code = params->n; count=1;
evKey/
new Code = (10 * new Code ) + par ams ->n; c ount++; [isCodeEnter ed() ] [else] evKeyOn[IS_IN(different) ]/ changeCode(); [IS_IN(cor rect)]/ itsController- >GEN(evTemporise); evKeyOn
evKeyOff [IS_IN(cor rect)]/ itsController- >GEN(evDisarm) ; tm(10000) evKeyOff [IS_IN(notEntered) ] [IS_IN(c orrect)] evKey On [is CodeCorrect()] [else] tm(3000) tm(3000) ev KeyOff tm(5000) evKey/
new Code = params->n; count=1;
evKey/
new Code = (10 * new Code ) + par ams ->n; c ount++;
[isCodeEnter ed() ]
Test Configuration
theHW:Hw
1
ILedCtrl ,ILightCtrl,ISi renC trl
IKeyListener,IMovem entListene r,IDoorListener
c trl
theAlarm Ctrl:AlarmController
1
«Facade»
ILedC trl,ILightCtrl,ISirenCtrl
hwCtrl
IDoorListener,IKeyLis tener,IMovementListener
hwObs erver
Slide 34
Rhapsody Implementation of a Port (1)
PORT:
hwObserver
IDoorListener «Interface» onDoor():void IKeyListener «Interface» onKey(n:int):void onKeyOff():void onKeyOn():void onArm():void onDisarm():void IMovementListener «Interface» onMovement():voidIDoorListener, IKeyListener, IMovementListener
AlarmController
hwObserver_C::InBound_C
Auto generated
Port Class
Rhapsody Implementation of a Port (2)
PORT:
hwCtrl
ILedCtrl, ILIghtCtrl, ISirenCtrl
ILedCtrl
«Interface»setLed(ident:tLed,state:tOnOff)...
ILightCtrl
«Interface»setLight(aLight:tLights,stat...
ISirenCtrl
«Interface»setSiren(state:tOnOff):void
Auto generated
AlarmController
Slide 36
Rhapsody Implementation of a Port (3)
PORT:
hwObserver
IDoorListener, IKeyListener,
IMovementListener
hwObserver_C
InBound_C
OutBound_C
x
IDoorListener
IKeyListener
IMovementListener
hwCtrl_C
InBound_C
OutBound_C
x
ILedCtrl
ILightCtrl
ISirenCtrl
PORT:
hwCtrl
ILedCtrl, ILIghtCtrl,
ISirenCtrl
Rhapsody Implementation of a Port (4)
theAlarmCrtl: AlarmController
hwCtrl: hwCtrl_C
hwObserver: hwObserver_C
InBound: InBound_C
OutBound: OutBound_C
theHW: Hw
ctrl:ctrl_C
InBound: InBound_C
OutBound: OutBound_C
Slide 38
Test Setup
AlarmController theAlarmCtrl;
Hw theHW;
theHW
.getCtrl()->setItsIKeyListener(
theAlarmCtrl
.
getHwObserver()
->getItsIKeyListener());
theHW.
getCtrl()->setItsIMovementListener(
theAlarmCtrl
.
getHwObserver()
->getItsIMovementListener());
theHW
.getCtrl()->setItsIDoorListener(
theAlarmCtrl
.
getHwObserver()
->getItsIDoorListener());
theAlarmCtrl
.getHwCtrl()->setItsILedCtrl(
theHW
.getCtrl()->getItsILedCtrl());
theAlarmCtrl
.getHwCtrl()->setItsILightCtrl(
theHW
.getCtrl()->getItsILightCtrl());
UML 2.0 Component Diagram
Gui
«Executable»
AlarmCtrlLib
HWAbsLib
<<Usage>>
<<Usage>>
Slide 40
Summary
Component patterns and ports:
–
Component-Based Architecture
–
ROOM Pattern (=>UML 2.x Ports)