任何人都有Quick Sequence Diagram Editor的经验?即时显示+文本源代码+ Java实现的组合对我来说很有吸引力,但是我不太清楚如何使语法达到我想要的效果,并且文档也不是很清楚。这是一个人为的例子:

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
al:atm.what time is it
atm:al.it's now
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?
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
al:atm.what about my $10?
atm:al.read my lips: you only have $3

这是单线程模式下QSDE的结果:

并在多线程模式下:

我想我不清楚是什么开始/结束那些竖线。我遇到的情况是单线程,但是涉及到状态,并且所有消息都是异步的。我想这意味着我应该使用一个外部对象来表示该状态及其生命周期。我想要的是一个时间轴来表示消息序列
  • al:atm.give me $ 10
  • atm:bank.check al的帐户余额
  • bank:atm.al有$ 3
  • atm:al。您只有$ 3

  • 另一个时间轴代表消息序列
  • bill:atm.give me $ 20
  • atm:bank.check帐单的帐户余额
  • bank:atm.bill有$ 765
  • atm:bank.hmm您确定吗?
  • bank:atm.yes我敢肯定,帐单上有$ 765
  • atm:bill。这是20美元,现在消失了
  • atm:bank。我刚给了Bill $ 20
  • bank:atm.great,他是一个很酷的家伙

  • 另一个“wisecracks”代表我现在不在乎的其他杂项消息。

    有没有办法用QSDE做到这一点?

    最佳答案

    当启动新线程时(并且来自用户的消息始终会启动新线程),直到明确将其停止或该图结束之前,它不会停止。例如。 atm:stop终止atm线程

    这是第一次尝试
    (一切都在多线程模式下):

    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
    

    带有异步消息的另一个版本

    (可以说,消息应该是异步的,因为它们是通过网络传输的。无论如何,现在所有箭头看起来都一样)

    消息开头的“>”将启动一个新线程(默认情况下,来自用户和进程的所有消息都将启动一个新线程。)

    最后的“&”表示调用立即返回,并且不显示新线程。您可以使用它来模拟将消息发送到现有线程。
    (默认情况下,发送给用户和进程的所有消息总是立即返回。)
    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
    

    具有所有明智选择的完整示例

    从示例中尚不清楚何时确切停止ATM中的线程。 ATM似乎更像是用户或进程,而不是对象。因此,该示例不一定有意义
    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
    

    关于sequence-diagram - 将快速序列图编辑器用于序列图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1850096/

    10-11 11:59