Assuming module foo
with method bar
:
import foo
method_to_call = getattr(foo, 'bar')
result = method_to_call()
You could shorten lines 2 and 3 to:
result = getattr(foo, 'bar')()
if that makes more sense for your use case.
You can use getattr
in this fashion on class instance bound methods, module-level methods, class methods... the list goes on.
When a new thread is started (and a message from an user always starts a new thread) it does not stop until it is explicitly stopped or until the diagram ends. E.g. atm:stop terminates the atm thread
here a first attempt
(everything in multithreaded mode):
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm.give me $10
atm:al has $3=bank.check al's account balance
atm:al.you only have $3
atm:stop
bill:atm.give me $20
atm:bill has $765=bank.check bill's account balance
atm:yes I'm sure, bill has $765=bank.hmm are you sure?
atm:bill.here's $20, now go away
atm:great, he's a cool dude=bank.I just gave Bill $20
another version with asynchronous messages
(arguably the messages should be asynchronous, since they are transmitted over the network. Anyway now all arrows look the same)
">" at the start of a message starts a new thread (all messages from users and processes start a new thread by default.)
"&" at the end means that the call returns immediately, and the new thread is not shown. you can use this to simulate sending messages to existing threads.
(all messages TO users and processes always return immediately by default. )
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm.give me $10
atm:>bank.check al's account balance
bank:>atm.al has $3&
bank:stop
atm:al.you only have $3
atm:stop
bill:atm.give me $20
atm:>bank.check bill's account balance
bank:>atm.bill has $765&
bank:stop
atm:>bank.hmm are you sure?
bank:>atm.yes I'm sure, bill has $765&
bank:stop
atm:bill.here's $20, now go away
atm:>bank.I just gave Bill $20
bank:>atm.great, he's a cool dude&
bank:stop
The full example with all the wisecracks
it is unclear from the example when exactly a thread in ATM should stop. ATM seems to be acting more like a user or process, not an object. So the example does not necessarily make sense
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm[a].give me $10
atm:al has $3=bank.check al's account balance
al:atm.what time is it
atm:al.it's now
atm:stop
atm:al.stop bugging me
atm:al.you only have $3
atm:bill.and don't you open your mouth
bill:atm.who asked you?&
atm:stop
bill:atm.give me $20
al:atm.hey, I'm not finished!&
atm:bill has $765=bank.check bill's account balance
atm:yes I'm sure, bill has $765=bank.hmm are you sure?
atm:bill.here's $20, now go away
atm:great, he's a cool dude=bank.I just gave Bill $20
atm:_
atm:stop
al:atm.what about my $10?
atm:al.read my lips: you only have $3
Best Answer
Here are examples of recursive calls: self message(non recursive) vs self recursive message
Tool support is also given, for example: http://www.sparxsystems.com/enterprise_architect_user_guide/9.0/standard_uml_models/recursion.html
I think I'd not specify a recursive call unless I am really sure I need the call to be recursive. Then the developer may decide for himself whether to implement a recursive call or an iteration. If I need the recursion, a hint (using a note) might be helpful.