Object subclass: #BBFacility instanceVariableNames: 'limit loan shares' classVariableNames: '' poolDictionaries: '' category: 'BBLoanSyndicate-Data'! !BBFacility methodsFor: 'initialization' stamp: 'sumim 1/23/2013 11:19'! initialize shares := Dictionary new! ! !BBFacility methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! limit "Answer the value of limit" ^ limit! ! !BBFacility methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! limit: anObject "Set the value of limit" limit := anObject! ! !BBFacility methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! loan "Answer the value of loan" ^ loan! ! !BBFacility methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! loan: anObject "Set the value of loan" loan := anObject! ! !BBFacility methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! shares "Answer the value of shares" ^ shares! ! !BBFacility methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! shares: anObject "Set the value of shares" shares := anObject! ! Object subclass: #BBLoan instanceVariableNames: 'shares' classVariableNames: '' poolDictionaries: '' category: 'BBLoanSyndicate-Data'! !BBLoan methodsFor: 'initialization' stamp: 'sumim 1/23/2013 11:19'! initialize shares := Dictionary new! ! !BBLoan methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! shares "Answer the value of shares" ^ shares! ! !BBLoan methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! shares: anObject "Set the value of shares" shares := anObject! ! BB1Context subclass: #BBLoanSyndicate instanceVariableNames: 'facility' classVariableNames: '' poolDictionaries: '' category: 'BBLoanSyndicate-Context'! !BBLoanSyndicate methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! facility "Answer the value of facility" ^ facility! ! !BBLoanSyndicate methodsFor: 'accessing' stamp: 'sumim 1/23/2013 11:21'! facility: anObject "Set the value of facility" facility := anObject! ! !BBLoanSyndicate methodsFor: 'role binding' stamp: 'sumim 1/23/2013 11:31'! AmountPie ^facility loan! ]style[(9 1 15)f2b,f2i,f2! ! !BBLoanSyndicate methodsFor: 'role binding' stamp: 'sumim 1/23/2013 11:31'! Lender ^facility! ]style[(6 1 13)f2b,f2i,f2! ! !BBLoanSyndicate methodsFor: 'role binding' stamp: 'sumim 1/23/2013 11:31'! PercentagePie ^facility! ]style[(13 1 10)f2b,f2i,f2! ! !BBLoanSyndicate methodsFor: 'initialization' stamp: 'sumim 1/23/2013 11:34'! buildFacility facility := BBFacility new. facility loan: BBLoan new.! ! !BBLoanSyndicate methodsFor: 'initialization' stamp: 'sumim 1/23/2013 11:34'! joinFacility: company percentage: int facility shares at: company put: int. facility loan shares at: company put: 0! ! !BBLoanSyndicate methodsFor: 'triggers' stamp: 'sumim 1/23/2013 11:35'! draw: amount self triggerInteractionFrom: #Lender with: #draw: andArgs: {amount}! ]style[(5 17 23 1 8 5 8 8 9)bf3,f3,f2,f3b,f3,f2,f3,f2,f3! ! !BBLoanSyndicate methodsFor: 'triggers' stamp: 'sumim 1/23/2013 11:36'! pay: amount self triggerInteractionFrom: #Lender with: #pay: andArgs: {amount}! ]style[(4 78)bf3,f3! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! BBLoanSyndicate class instanceVariableNames: ''! !BBLoanSyndicate class methodsFor: 'context diagram' stamp: 'sumim 1/23/2013 11:27'! linkBreakPoints | dict | (dict := Dictionary new) yourself. ^dict.! ! !BBLoanSyndicate class methodsFor: 'context diagram' stamp: 'sumim 1/23/2013 11:27'! rolePositions | dict | (dict := Dictionary new) at: #PercentagePie put: 350@167; at: #Lender put: 107@101; at: #AmountPie put: 281@60; yourself. ^dict.! ! !BBLoanSyndicate class methodsFor: 'role structure' stamp: 'sumim 1/23/2013 11:27'! roleStructure ^super roleStructure at: #PercentagePie put: #(); at: #Lender put: #(#AmountPie ); at: #AmountPie put: #(#PercentagePie ); yourself.! ! BB1RuntimeRole subclass: #BBLoanSyndicateAmountPie instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'BBLoanSyndicate-Roles'! BBLoanSyndicateAmountPie SoleInstance: ((BBLoanSyndicateAmountPie basicNew instVarAt: 1 put: #BBLoanSyndicate; yourself))! !BBLoanSyndicateAmountPie methodsFor: 'role methods' stamp: 'sumim 1/23/2013 11:28'! decrease: amount | shares total | shares := self shares. total := shares sum asFloat. shares keysDo: [:company | | current | current := shares at: company. shares at: company put: current - (amount * (current / total))]! ! !BBLoanSyndicateAmountPie methodsFor: 'role methods' stamp: 'sumim 1/23/2013 11:28'! increase: amount PercentagePie shares associationsDo: [:assoc | | company percentage | company := assoc key. percentage := assoc value / 100 asFloat. self shares at: company put: (self shares at: company) + (amount * percentage)]! ! BB1RuntimeRole subclass: #BBLoanSyndicateLender instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'BBLoanSyndicate-Roles'! BBLoanSyndicateLender SoleInstance: ((BBLoanSyndicateLender basicNew instVarAt: 1 put: #BBLoanSyndicate; yourself))! !BBLoanSyndicateLender methodsFor: 'role methods' stamp: 'sumim 1/23/2013 11:28'! draw: amount AmountPie increase: amount. self limit: self limit - amount! ! !BBLoanSyndicateLender methodsFor: 'role methods' stamp: 'sumim 1/23/2013 11:28'! pay: amount AmountPie decrease: amount. self limit: self limit + amount! ! Object subclass: #BBLoanSyndicateTesting instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'BBLoanSyndicate-Testing'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! BBLoanSyndicateTesting class instanceVariableNames: ''! !BBLoanSyndicateTesting class methodsFor: 'examples' stamp: 'sumim 1/23/2013 11:39'! example "BBLoanSyndicateTesting example" | syndicate | syndicate := BBLoanSyndicate new buildFacility. syndicate joinFacility: #A percentage: 50. syndicate joinFacility: #B percentage: 30. syndicate joinFacility: #C percentage: 20. syndicate facility limit: 100000. syndicate draw: 10000. syndicate pay: 5000. World findATranscript: nil. syndicate facility loan shares associations sort do: [:assoc | Transcript cr; show: assoc]! !