Asmbler
k
LIFIA-DepartamentodeInformática,FacultaddeCienciasExactas,UNLP
CC11(1900)LaPlata,BuenosAires,Argentina
[gaston,fede]@
Tel/Fax:(54)(21)228252
1.-PatternName
Asmbler
2.-AlsoKnownAs
Grouper/Packager
3.-Intent
Provideanobjectartifactresponsibletogroupacollectionofobjects,
resultingobjectorcollectionofobjectsmaybepartofanewcollectiontoasmbleagain.
4.-Motivation
ItiscommoninfinancialapplicationstofindtherequirementtogroupTransactions,TransactionFundSplits
(TransactionFundSplitsreprentsthesplitpaymenttodifferentcounterpartaccounts)orInstrumentsin
otherobjects.
SometimestheurofatradesupportapplicationneedstogroupTransactionswiththesameCounterpart
ultisanewfinancialobjectthatencapsulatesthe
henewfinancialobjectsarepolymorphicwiththeinitialones,thettlement
xistsawell-definedlectioncriterioninorderto
grouptheobjects;intheexampleabovethecriteriawasbycounterpart+maturityDate.
rtimes,thiscriteriaishardcoded
intosomemethodofadomainobject.
Wepropotomodelthelectioncriteriaasacomponentthatwillbeudbyanasmblerobjectinorder
mponentcanbereplacedbyotherlectioncriteriawithoutaffectingthe
inancialmodel1(eFig1.)instancesofclassNetteractslikeanasmbler,while
instancesofNetTransactionFundSplitplaytheasmbledobjectrole.
AbstractTransactionFundSplit
price()
tradeDate()
Client
elements()
Netter
netElements(col)
NetTransactionFundSplit
ttlementDate
quantity
price
TransactionFundSplit
fund
amount
quantity
NettingCriteria
lectFrom:aCollfor:aNet
canBeNetted:anObjwith:baObj
^lfnettingAlgorithmprice
NettingAlgorithm
quantity
price
“lectfromaColltho
objectsthatcouldbe
addedtoaNettedObject”
“AnswerifanObj
canbenetted
withbaObj”
uctureofthefinancialimplementationoftheAsmblerpattern
doingfinancialapplications(trade,
confirmation&ttlementoftransactions)implementedinVisualWorkswithENVY/Developerand
SybaRDBMS
PartoftheknowledgeoftheNetTransactionFundSplitisbadonthecomputingofagivenaspectofthe
groupedelements,suchas:price,quantity,,itispossibletodefineoperationstocomputethe
transformations.
Weusblemwiththis
approachisthatitisdifficulttoreutheasmbledobjectsinceitistightlycoupledwiththecontextwhere
otosplitthisknowledgeinanewobjectcalledCalculationAlgorithmwhichisa
privatecollaboratoroftheasmbledobject(inourmodelTransactionFundSplit).Theasmbledobject
delegatestotheCalculationAlgorithmtheresponsibilitytorespondtosomemessages.
5.-Applicability
UtheAsmblerpatternwhen:
•
•
•
The
resultingtisanewabstraction,Thatisbadonitscomponents.
Thelectioncriteria'salgorithmshouldbeindependentandmaybereplacedbyanotherone.
TheAsmbledObjectwantstobeudinmanycontextswithouthavingtomodifyit.
6.-Structure
hegeneralstructureoftheAsmblerpattern.
AbstractBaObject
aspectA
aspectB
aspectC
Client
elements
elements:aColl
Asmbler
netElements:aColl
AsmbledObject
add:anElement
aspectA
aspectB
BaObject
aspectA
aspectB
GroupingCriteria
canNet:with:
CalculationAlgorithm
aspectA
eralstructureoftheAsmblerpattern
7.-Participants
•Asmbler(Netter)
-Definesaninterfaceforreceivingtheobjectstogroup.
-DefinesaninterfaceforreceivingtheGroupingCriteria.
-ConstructsandasmblesAsmbledObjectsfromaninitialcollectionofobjectsaccording
totheGroupingCriteria.
•GroupingCriteria(NettingCriteria)
-Specifieswhichobjectscouldbegroupedaccordingtothecriteria.
•AsmbledObject(NettedObject)
-Implementsthedefaultbehaviorforitsinterfaceaccordingtothehierarchywhereitbelongs.
-ImplementstheCollectioninterface(#add:,#addAll:,#includes:,etc.).
-HoldsareferencetotheGroupingCriteriaudtobuilditlf.
-HoldsareferencetotheCalculationAlgorithmtouinordertorespondtosomemessages.
•CalculationAlgorithm(NettingAlgorithm)
-ImplementsthebehaviornecessarytocalculatesomeaspecsoftheAsmbledObject
8.-Collaborations
•TheClientcreaty
beaccomplishedwithaBuilder(refertotheBuilderpatternformoreinformation[Gamma95]).The
Clientmustalsoprovidethecollectionofobjectstogroup.
•TheAsmbleraskstheGroupCriteriatolectwhichobjectsofthecollectioncouldbegroupedinan
AsmbledObject.
•TheAsmblerrequeststheAsmbledObjectclasstocreateanewinstancewhichwillcontainagiven
collectionofobjectsaccordingtoaGroupingCriteria.
•TheAsmbledObjectcollaborateswiththeCalculationAlgorithminordertorespondtosome