UML Distilled (UML精粹)

Edit


我有史以来,见过的翻译的最最最烂的中文译本,没有之一。大家记住这个名字徐家福。通篇狗屁不通半文半白的叙述,业务不精还以为自己是孔圣人。每次看他的译本就有真想抽丫的冲动。
书是好书,Martin Fowler-很有经验的UML专家。书中不乏他关于使用UML的真知灼见。刚阅览了第九章,忍不住要写点笔记记录一下。

Chapter 8. Deployment Diagrams

The nodes contain artifacts, which are the physical manifestations of software: usually, files. These files might be executables (such as .exe files, binaries, DLLs, JAR files, assemblies, or scripts), or data files, configuration files, HTML documents, and so on. Listing an artifact within a node shows that the artifact is deployed to that node in the running system.

Chapter 9. Use Cases

Use cases are well known as an important part of the UML. However, the surprise is that in many ways, the definition of use cases in the UML is rather sparse.

Use case在UML中很重要,但他的定义却比较随意。

What the UML describes is a use case diagram, which shows how use cases relate to each other.

UML中提到的use case,往往指的是用例图,但其实用例图用处并不大,真正重要的use case本身,按Martin的说发就是,那一条条的steps和extensions。

定义

Use Scenario

A scenario is a sequence of steps describing an nteraction between a user and a system.

Use Case

Use cases are a technique for capturing the functional requirements of a system.
A use case is a set of scenarios tied together by a common user goal.
Use Case = several Use Scenarios

Extension

An extension within the use case names a condition that results in different interactions from those described in the main success scenario (MSS) and states what those differences are.

翻成扩展吧,感觉就是steps中的特例。具体可以看下面的例子。

Levels

这个很有意思。按Martin的说法,分成三个level

  • Sea Level
    • Sea-level use cases typically represent a discrete interaction between a primary actor and the system.
  • Fish Level
    • Use cases that are there only because they are included by sea-level use cases are fish level. Sea level的子use case,被sea level use case包含。
  • Kite Level
    • kite-level use cases show how the sea-level use cases fit into wider business interactions. 在business case的时候用到这个level的use case。

Fowler大师给出建议:

You should have most of your use cases at the sea level.

在系统设计的时候,尽量只用sea level的use case,也就是中间级,既不是太细也不太粗。

Feature

Many approaches use features of a system—Extreme Programming calls them user stories—to help describe requirements.

所谓Feature,我理解,是系统的特性,根据use case要用到的特性来定义系统需要提供什么,这是一种对正在设计的系统的requirement。
但是Feature本身与use case并没有对应关系,他们是系统设计时,先后被用到的两个用途的两件东西。现有use case,再有features (user stories)。我认为feature这个词更贴切,以区分use case。

Fowler大师再次给出建议:

Although you can go directly to describing features, many people find it helpful to develop use cases first and then generate a list of features.

Misc.

  • A pre-condition describes what the system should ensure is true before the system allows
    the use case to begin. This is useful for telling the programmers what conditions they don’t
    have to check for in their code.
  • A guarantee describes what the system will ensure at the end of the use case. Success guarantees hold after a successful scenario; minimal guarantees hold after any scenario.
  • A trigger specifies the event that gets the use case started.

这些在严格定义use case,并促成系统界限设定时用得上。
此时Fowler大师再次给出建议:

It’s better to do too little than too much. The amount of detail you need in a use case depends on the amount of risk in that use case.

后面Fowler大师接着说(我就不放原文了),通常,在开始的时候,你只需要几个关键的use case,慢慢地其他的use case会被添进来。你并不需要把他们都写下来,口头的交流效率往往更高。
不要花太多的时间画用例图,focus在文字描述上。画图容易让事情变得复杂而失去焦点,并且图越复杂,看得懂的人越少。

例子

什么时候用Use Case

Use cases are a valuable tool to help understand the functional requirements of a system.

接着Fowler大师又给出真知灼见:

A couple of pages per use case is just fine for most cases.

一般一个use case一到两页纸足矣。不要太多或太少。

Chapter 10. State Machine Diagrams

When to Use State Diagrams

State diagrams are good at describing the behavior of an object across several use cases. State diagrams are not very good at describing behavior that involves a number of objects collaborating.
Many people find that UI and control objects have the kind of behavior that is useful to depict with a state diagram.

例子&基本概念

When developers talk about objects, they often refer to the state of the objects to mean the combination of all the data in the fields of the objects.

开发人员说的object,一般指的是object的某一个状态。

高级概念

Internal Activities

Activity States

regular activities occur “instantaneously” and cannot be interrupted by regular events, while do-activities can take finite time and can be interrupted

Superstates

Concurrent States

history pseudostate. This indicates that when the clock is switched on, the radio/CD choice goes back to the state the clock was in when it was turned off.上一次关机时的状态,就是history pseudostate。

Implementing State Diagrams

有三个方法implement

  • nested switch
  • the State pattern
  • state tables
    第一个最简单也最常见就是switch-case。Fowler大师说不建议用这个,即便是简单的case。因为很容易失控。
    第二个是state设计模式,具体请见[Gang of Four]The state pattern is easier to put together when you need it, and although it needs a new class for each state, it’s a small amount of code to write in each case.

Obviously, the state table is more work to do once, but then you can use it every time you have a state problem to hold.

Chapter 11. Activity Diagrams

基本概念

我翻译之为活动图。其最重要的功能就是阐明动作序列——串行&并行。

  • Initial node & activity final
  • fork & join
  • decision & merge
  • 每一个圆角的方框框是一个action,所有的这一切组成一个activity

如果需要每一个action可以转化成一个子活动(sub activity)。然后在主图中用一个叉子(rake)表示。

When to Use Activity Diagrams

The great strength of activity diagrams lies in the fact that they support and encourage parallel behavior.

不过在这一章节中,Fowler大师这里有一段话颇为耐人寻味:

In principle, you can take advantages of the forks and joins to describe parallel algorithms for concurrent programs. Although I don’t travel in concurrent circles that much, I haven’t seen much evidence of people using them there.
I think the reason is that **most of the complexity of concurrent programming is in avoiding
contention on data, and activity diagrams don’t help much with that**.

并没有很多人或者有很强的理由使用活动图来描述并行结构,原因是活动图并不能很好的描述对资源的争夺(contention)。

高级用法

Partitions

通过泳道图来阐明actions都由哪写object来完成的。这个对阐述流程的时候没什么用,但是在business process modeling的时候比较有用,可以清楚的表明,每个部门或者角色需要做哪些事情。典型的partitions如下图

Signals

这个在描述流程的时候比较有用。他提供了一种活动起点的描述。比方,系统响应一个外部事件,来开始一个activity。下面是例子

  • send signal
  • accept signal
  • time signal

Tokens

这个按照Fowler大师的说法,有些UML的大部头著作花了大篇幅的文章介绍token的使用。在复杂系统中token可以让系统可易于理解,可视化更好。

You can visualize the tokens with coins or counters moving across the diagram. As you get to more complicated examples of activity diagrams, tokens often make it easier to visualize things.

Flows and Edges

这里提供了几种图例,来丰富活动图的画法。看例子就可以了:

Pins and Transformations

看一个pin and transformation的例图:

Pins are best when you want to look at the data needed and produced by the various actions.
If you use pins, it’s safe to show multiple flows coming into the same action. The pin notation
reinforces the implicit join

Expansion Regions

这个主要用来描述一个activity的输出会触发若干个activity。看例图:

Flow Final

Flow Final提供了提前结束一个activity分支的描述。看下面的例子,有一个分支在某一情况下,直接结束了。

Join Specifications

join之前的判断

总得看来,activity diagram可以用来画flow chart,而且提供了一下更酷的功能。

%23UML%20Distilled%20%28UML%u7CBE%u7CB9%29%0A@%28%u5B66%u4E60%u7B14%u8BB0%29%5BUML%5D%0A%u6211%u6709%u53F2%u4EE5%u6765%uFF0C%u89C1%u8FC7%u7684%u7FFB%u8BD1%u7684%u6700%u6700%u6700%u70C2%u7684%u4E2D%u6587%u8BD1%u672C%uFF0C%u6CA1%u6709%u4E4B%u4E00%u3002%u5927%u5BB6%u8BB0%u4F4F%u8FD9%u4E2A%u540D%u5B57%u5F90%u5BB6%u798F%u3002%u901A%u7BC7%u72D7%u5C41%u4E0D%u901A%u534A%u6587%u534A%u767D%u7684%u53D9%u8FF0%uFF0C%u4E1A%u52A1%u4E0D%u7CBE%u8FD8%u4EE5%u4E3A%u81EA%u5DF1%u662F%u5B54%u5723%u4EBA%u3002%u6BCF%u6B21%u770B%u4ED6%u7684%u8BD1%u672C%u5C31%u6709%u771F%u60F3%u62BD%u4E2B%u7684%u51B2%u52A8%u3002%0A%u4E66%u662F%u597D%u4E66%uFF0CMartin%20Fowler-%u5F88%u6709%u7ECF%u9A8C%u7684UML%u4E13%u5BB6%u3002%u4E66%u4E2D%u4E0D%u4E4F%u4ED6%u5173%u4E8E%u4F7F%u7528UML%u7684%u771F%u77E5%u707C%u89C1%u3002%u521A%u9605%u89C8%u4E86%u7B2C%u4E5D%u7AE0%uFF0C%u5FCD%u4E0D%u4F4F%u8981%u5199%u70B9%u7B14%u8BB0%u8BB0%u5F55%u4E00%u4E0B%u3002%0A%0A%5BTOC%5D%0A%0A%23%23Chapter%208.%20Deployment%20Diagrams%0A%21%5BAlt%20text%5D%28./1470561176490.png%29%0A%3EThe%20nodes%20contain%20artifacts%2C%20which%20are%20the%20physical%20manifestations%20of%20software%3A%20usually%2C%20files.%20These%20files%20might%20be%20executables%20%28such%20as%20.exe%20files%2C%20binaries%2C%20DLLs%2C%20JAR%20files%2C%20assemblies%2C%20or%20scripts%29%2C%20or%20data%20files%2C%20configuration%20files%2C%20HTML%20documents%2C%20and%20so%20on.%20Listing%20an%20artifact%20within%20a%20node%20shows%20that%20the%20artifact%20is%20deployed%20to%20that%20node%20in%20the%20running%20system.%0A%23%23Chapter%209.%20Use%20Cases%0A%3EUse%20cases%20are%20well%20known%20as%20an%20important%20part%20of%20the%20UML.%20However%2C%20the%20surprise%20is%20that%20in%20many%20ways%2C%20the%20definition%20of%20use%20cases%20in%20the%20UML%20is%20rather%20sparse.%20%0A%0AUse%20case%u5728UML%u4E2D%u5F88%u91CD%u8981%uFF0C%u4F46%u4ED6%u7684%u5B9A%u4E49%u5374%u6BD4%u8F83%u968F%u610F%u3002%0A%3EWhat%20the%20UML%20describes%20is%20a%20use%20case%20diagram%2C%20which%20shows%20how%20use%20cases%20relate%20to%20each%20other.%20%0A%0AUML%u4E2D%u63D0%u5230%u7684use%20case%uFF0C%u5F80%u5F80%u6307%u7684%u662F%u7528%u4F8B%u56FE%uFF0C%u4F46%u5176%u5B9E%u7528%u4F8B%u56FE%u7528%u5904%u5E76%u4E0D%u5927%uFF0C%u771F%u6B63%u91CD%u8981%u7684use%20case%u672C%u8EAB%uFF0C%u6309Martin%u7684%u8BF4%u53D1%u5C31%u662F%uFF0C%u90A3%u4E00%u6761%u6761%u7684steps%u548Cextensions%u3002%0A%23%23%23%u5B9A%u4E49%0A%23%23%23%23Use%20Scenario%0A%3EA%20scenario%20is%20a%20sequence%20of%20steps%20describing%20an%20nteraction%20between%20a%20user%20and%20a%20system.%20%0A%23%23%23%23Use%20Case%0A%3EUse%20cases%20are%20a%20technique%20for%20capturing%20the%20functional%20requirements%20of%20a%20system.%20%0A%3EA%20use%20case%20is%20a%20set%20of%20scenarios%20tied%20together%20by%20a%20common%20user%20goal.%0A%3E**Use%20Case%20%3D%20several%20Use%20Scenarios**%0A%23%23%23%23Extension%0A%3EAn%20extension%20within%20the%20use%20case%20names%20a%20condition%20that%20results%20in%20different%20interactions%20from%20those%20described%20in%20the%20main%20success%20scenario%20%28MSS%29%20and%20states%20what%20those%20differences%20are.%0A%0A%u7FFB%u6210%u6269%u5C55%u5427%uFF0C%u611F%u89C9%u5C31%u662Fsteps%u4E2D%u7684%u7279%u4F8B%u3002%u5177%u4F53%u53EF%u4EE5%u770B%u4E0B%u9762%u7684%u4F8B%u5B50%u3002%0A%23%23%23%23Levels%0A%u8FD9%u4E2A%u5F88%u6709%u610F%u601D%u3002%u6309Martin%u7684%u8BF4%u6CD5%uFF0C%u5206%u6210%u4E09%u4E2Alevel%0A-%20Sea%20Level%0A%09-%20%20Sea-level%20use%20cases%20typically%20represent%20a%20discrete%20interaction%20between%20a%20primary%20actor%20and%20the%20system.%0A-%20Fish%20Level%0A%09-%20Use%20cases%20that%20are%20there%20only%20because%20they%20are%20included%20by%20sea-level%20use%20cases%20are%20fish%20level.%20Sea%20level%u7684%u5B50use%20case%uFF0C%u88ABsea%20level%20use%20case%u5305%u542B%u3002%0A-%20Kite%20Level%0A%09-%20kite-level%20use%20cases%20show%20how%20the%20sea-level%20use%20cases%20fit%20into%20wider%20business%20interactions.%20%u5728business%20case%u7684%u65F6%u5019%u7528%u5230%u8FD9%u4E2Alevel%u7684use%20case%u3002%0A%0AFowler%u5927%u5E08%u7ED9%u51FA%u5EFA%u8BAE%uFF1A%0A%3E**You%20should%20have%20most%20of%20your%20use%20cases%20at%20the%20sea%20level.%20**%0A%0A%u5728%u7CFB%u7EDF%u8BBE%u8BA1%u7684%u65F6%u5019%uFF0C%u5C3D%u91CF%u53EA%u7528sea%20level%u7684use%20case%uFF0C%u4E5F%u5C31%u662F%u4E2D%u95F4%u7EA7%uFF0C%u65E2%u4E0D%u662F%u592A%u7EC6%u4E5F%u4E0D%u592A%u7C97%u3002%0A%23%23%23%23Feature%0A%3EMany%20approaches%20use%20features%20of%20a%20system%u2014Extreme%20Programming%20calls%20them%20**user%20stories**%u2014to%20help%20describe%20requirements.%20%0A%0A%u6240%u8C13Feature%uFF0C%u6211%u7406%u89E3%uFF0C%u662F%u7CFB%u7EDF%u7684%u7279%u6027%uFF0C%u6839%u636Euse%20case%u8981%u7528%u5230%u7684%u7279%u6027%u6765%u5B9A%u4E49%u7CFB%u7EDF%u9700%u8981%u63D0%u4F9B%u4EC0%u4E48%uFF0C%u8FD9%u662F%u4E00%u79CD%u5BF9%u6B63%u5728%u8BBE%u8BA1%u7684%u7CFB%u7EDF%u7684requirement%u3002%0A%u4F46%u662FFeature%u672C%u8EAB%u4E0Euse%20case%u5E76%u6CA1%u6709%u5BF9%u5E94%u5173%u7CFB%uFF0C%u4ED6%u4EEC%u662F%u7CFB%u7EDF%u8BBE%u8BA1%u65F6%uFF0C%u5148%u540E%u88AB%u7528%u5230%u7684%u4E24%u4E2A%u7528%u9014%u7684%u4E24%u4EF6%u4E1C%u897F%u3002%u73B0%u6709use%20case%uFF0C%u518D%u6709features%20%28user%20stories%29%u3002%u6211%u8BA4%u4E3Afeature%u8FD9%u4E2A%u8BCD%u66F4%u8D34%u5207%uFF0C%u4EE5%u533A%u5206use%20case%u3002%0A%0AFowler%u5927%u5E08%u518D%u6B21%u7ED9%u51FA%u5EFA%u8BAE%uFF1A%0A%3EAlthough%20you%20can%20go%20directly%20to%20describing%20features%2C%20many%20people%20find%20it%20helpful%20to%20**develop%20use%20cases%20first%20and%20then%20generate%20a%20list%20of%20features.**%20%0A%0A%23%23%23%23Misc.%0A-%20A%20**pre-condition**%20describes%20what%20the%20system%20should%20ensure%20is%20true%20before%20the%20system%20allows%0Athe%20use%20case%20to%20begin.%20This%20is%20useful%20for%20telling%20the%20programmers%20what%20conditions%20they%20don%27t%0Ahave%20to%20check%20for%20in%20their%20code.%0A-%20A%20**guarantee**%20describes%20what%20the%20system%20will%20ensure%20at%20the%20end%20of%20the%20use%20case.%20Success%20guarantees%20hold%20after%20a%20successful%20scenario%3B%20minimal%20guarantees%20hold%20after%20any%20scenario.%0A-%20A%20**trigger**%20specifies%20the%20event%20that%20gets%20the%20use%20case%20started.%0A%0A%u8FD9%u4E9B%u5728%u4E25%u683C%u5B9A%u4E49use%20case%uFF0C%u5E76%u4FC3%u6210%u7CFB%u7EDF%u754C%u9650%u8BBE%u5B9A%u65F6%u7528%u5F97%u4E0A%u3002%0A%u6B64%u65F6Fowler%u5927%u5E08%u518D%u6B21%u7ED9%u51FA%u5EFA%u8BAE%uFF1A%0A%3E**It%27s%20better%20to%20do%20too%20little%20than%20too%20much.%20The%20amount%20of%20detail%20you%20need%20in%20a%20use%20case%20depends%20on%20the%20amount%20of%20risk%20in%20that%20use%20case.%20**%0A%0A%u540E%u9762Fowler%u5927%u5E08%u63A5%u7740%u8BF4%uFF08%u6211%u5C31%u4E0D%u653E%u539F%u6587%u4E86%uFF09%uFF0C%u901A%u5E38%uFF0C%u5728%u5F00%u59CB%u7684%u65F6%u5019%uFF0C%u4F60%u53EA%u9700%u8981%u51E0%u4E2A%u5173%u952E%u7684use%20case%uFF0C%u6162%u6162%u5730%u5176%u4ED6%u7684use%20case%u4F1A%u88AB%u6DFB%u8FDB%u6765%u3002%u4F60%u5E76%u4E0D%u9700%u8981%u628A%u4ED6%u4EEC%u90FD%u5199%u4E0B%u6765%uFF0C%u53E3%u5934%u7684%u4EA4%u6D41%u6548%u7387%u5F80%u5F80%u66F4%u9AD8%u3002%0A**%u4E0D%u8981%u82B1%u592A%u591A%u7684%u65F6%u95F4%u753B%u7528%u4F8B%u56FE%uFF0Cfocus%u5728%u6587%u5B57%u63CF%u8FF0%u4E0A%u3002%u753B%u56FE%u5BB9%u6613%u8BA9%u4E8B%u60C5%u53D8%u5F97%u590D%u6742%u800C%u5931%u53BB%u7126%u70B9%uFF0C%u5E76%u4E14%u56FE%u8D8A%u590D%u6742%uFF0C%u770B%u5F97%u61C2%u7684%u4EBA%u8D8A%u5C11%u3002**%0A%23%23%23%u4F8B%u5B50%0A%21%5BAlt%20text%5D%28./1469631172614.png%29%0A%23%23%23%u4EC0%u4E48%u65F6%u5019%u7528Use%20Case%0A%3EUse%20cases%20are%20a%20valuable%20tool%20to%20help%20understand%20the%20functional%20requirements%20of%20a%20system.%20%0A%0A%u63A5%u7740Fowler%u5927%u5E08%u53C8%u7ED9%u51FA%u771F%u77E5%u707C%u89C1%uFF1A%0A%3EA%20couple%20of%20pages%20per%20use%20case%20is%20just%20fine%20for%20most%20cases.%0A%0A%u4E00%u822C%u4E00%u4E2Ause%20case%u4E00%u5230%u4E24%u9875%u7EB8%u8DB3%u77E3%u3002%u4E0D%u8981%u592A%u591A%u6216%u592A%u5C11%u3002%20%0A%23%23Chapter%2010.%20State%20Machine%20Diagrams%0A%23%23%23When%20to%20Use%20State%20Diagrams%0A%3EState%20diagrams%20are%20good%20at%20describing%20the%20behavior%20of%20**an%20object%20across%20several%20use%20cases**.%20State%20diagrams%20are%20not%20very%20good%20at%20describing%20behavior%20that%20involves%20a%20number%20of%20objects%20collaborating.%0A%3EMany%20people%20find%20that%20**UI%20and%20control%20objects**%20have%20the%20kind%20of%20behavior%20that%20is%20useful%20to%20depict%20with%20a%20state%20diagram.%0A%23%23%23%u4F8B%u5B50%26%u57FA%u672C%u6982%u5FF5%0A%21%5BAlt%20text%5D%28./1470056081607.png%29%0A%u7BAD%u5934%u4E0A%u7684%u6587%u5B57%u683C%u5F0F%u4E3A%60trigger-signature%20%5Bguard%5D/activity%60%uFF0C%u4F8B%u5982%60candle%20removed%5Bdoor%20closed%5D/reveal%20lock%60%uFF0C%u610F%u601D%u662F%u5F53%u95E8%u5173%u8D77%u6765%u7684%u65F6%u5019%28guard%29%uFF0C%u8721%u70DB%u88AB%u4ECE%u70DB%u53F0%u62FF%u8D70%28event%29%uFF0C%u9501%u5373%u663E%u73B0%u51FA%u6765%28activity%29%u3002%u8FD9%u4E09%u4E2A%u90E8%u5206%u5747%u4E3A%u53EF%u9009%u9879%uFF0C%u4E0D%u662F%u5FC5%u987B%u6709%u7684%u3002%u5982%u679C%u51E0%u4E2Atransision%u6709%u76F8%u540C%u7684event%u548Cactivity%uFF0C%u90A3%u4E48guard%u5FC5%u987B%u4E92%u65A5%uFF0C%u8FD9%u6837%u624D%u80FD%u786E%u5B9A%u8D70%u54EA%u4E2Atransision%u3002%0AFowler%u5927%u5E08%u8BF4%uFF1A%0A%3EWhen%20developers%20talk%20about%20objects%2C%20they%20often%20refer%20to%20the%20state%20of%20the%20objects%20to%20mean%20the%20combination%20of%20all%20the%20data%20in%20the%20fields%20of%20the%20objects.%0A%0A%u5F00%u53D1%u4EBA%u5458%u8BF4%u7684object%uFF0C%u4E00%u822C%u6307%u7684%u662Fobject%u7684%u67D0%u4E00%u4E2A%u72B6%u6001%u3002%0A%23%23%23%u9AD8%u7EA7%u6982%u5FF5%0A%23%23%23%23Internal%20Activities%0A%21%5BAlt%20text%5D%28./1470057983821.png%29%0A%u4ECE%u81EA%u5DF1%u5230%u81EA%u5DF1%u7684transision%u4E2D%u7684%u6D3B%u52A8%u90E8%u5206%u5C31%u662Finternal%20activity%u3002%0A%23%23%23%23Activity%20States%0A%21%5BAlt%20text%5D%28./1470058049870.png%29%0A%u8017%u65F6%u6BD4%u8F83%u957F%u7684activity%u672C%u8EAB%u4E5F%u53EF%u4EE5%u6210%u4E3A%u4E00%u4E2Astate%uFF0C%u4F8B%u5982searching%u3002%0A%3Eregular%20activities%20occur%20%22instantaneously%22%20and%20cannot%20be%20interrupted%20by%20regular%20events%2C%20while%20**do-activities%20can%20take%20finite%20time%20and%20can%20be%20interrupted**%0A%23%23%23%23Superstates%0A%21%5BAlt%20text%5D%28./1470058186471.png%29%0A%u591A%u4E2Astate%u5171%u4EAB%u76F8%u540C%u7684transition%u548Cinternal%20activities%uFF0C%u8FD9%u6837%u53EF%u4EE5%u62BD%u8C61%u51FAsuperstates%uFF0C%u7136%u540E%u653E%u5230%u4E00%u4E2A%u6846%u6846%u91CC%u3002%0A%23%23%23%23Concurrent%20States%0A%21%5BAlt%20text%5D%28./1470058339705.png%29%0A%u51E0%u4E2Astate%u53EF%u80FD%u662F%u6B63%u4EA4%u7684%uFF08orthogonal%uFF09%uFF0C%u5373%u53EF%u80FD%u662F%u5E76%u884C%u72B6%u6001%u3002%u8FD9%u65F6%u5019%u5C31%u80FD%u8FD9%u6837%u8868%u793A%u3002%0A%3E%20**history%20pseudostate**.%20This%20indicates%20that%20when%20the%20clock%20is%20switched%20on%2C%20the%20radio/CD%20choice%20goes%20back%20to%20the%20state%20the%20clock%20was%20in%20when%20it%20was%20turned%20off.%u4E0A%u4E00%u6B21%u5173%u673A%u65F6%u7684%u72B6%u6001%uFF0C%u5C31%u662Fhistory%20pseudostate%u3002%20%0A%23%23%23Implementing%20State%20Diagrams%0A%u6709%u4E09%u4E2A%u65B9%u6CD5implement%0A-%20%20nested%20switch%0A-%20%20the%20State%20pattern%0A-%20%20state%20tables%0A%u7B2C%u4E00%u4E2A%u6700%u7B80%u5355%u4E5F%u6700%u5E38%u89C1%u5C31%u662Fswitch-case%u3002Fowler%u5927%u5E08%u8BF4%u4E0D%u5EFA%u8BAE%u7528%u8FD9%u4E2A%uFF0C%u5373%u4FBF%u662F%u7B80%u5355%u7684case%u3002%u56E0%u4E3A%u5F88%u5BB9%u6613%u5931%u63A7%u3002%0A%u7B2C%u4E8C%u4E2A%u662Fstate%u8BBE%u8BA1%u6A21%u5F0F%uFF0C%u5177%u4F53%u8BF7%u89C1%uFF3BGang%20of%20Four%uFF3DThe%20state%20pattern%20is%20easier%20to%20put%20together%20when%20you%20need%20it%2C%20and%20although%20it%20needs%20a%20new%20class%20for%20each%20state%2C%20it%27s%20a%20small%20amount%20of%20code%20to%20write%20in%20each%20case.%0A%21%5BAlt%20text%5D%28./1470058566116.png%29%0A%u7B2C%u4E09%u4E2A%u662Fstate%20table%uFF0C%u5F62%u5982%uFF1A%0A%21%5BAlt%20text%5D%28./1470058643590.png%29%0A%3EObviously%2C%20the%20state%20table%20is%20more%20work%20to%20do%20once%2C%20but%20then%20you%20can%20use%20it%20every%20time%20you%20have%20a%20state%20problem%20to%20hold.%20%0A%0A%23%23Chapter%2011.%20Activity%20Diagrams%0A%23%23%23%u57FA%u672C%u6982%u5FF5%0A%u6211%u7FFB%u8BD1%u4E4B%u4E3A%u6D3B%u52A8%u56FE%u3002%u5176%u6700%u91CD%u8981%u7684%u529F%u80FD%u5C31%u662F%u9610%u660E%u52A8%u4F5C%u5E8F%u5217%u2014%u2014%u4E32%u884C%26%u5E76%u884C%u3002%0A%21%5BAlt%20text%5D%28./1469861506321.png%29%0A%u6211%u89C9%u5F97%u6D3B%u52A8%u56FE%u5176%u5B9E%u5C31%u662F%u6D41%u7A0B%u56FE%28flow%20chart%29%uFF0C%u4F5C%u8005%u8BF4activity%20diagram%u4E0Eflow%20chart%u7684%u4E3B%u8981%u5DEE%u522B%u5C31%u662F%uFF0Cactivity%20diagram%u6709%u6807%u51C6%u8BED%u8A00%u6765%u63CF%u8FF0%u5E76%u884C%u7684%u52A8%u4F5C%u3002%0A%u4E00%u526F%u6D3B%u52A8%u56FE%u4E2D%u7684%u57FA%u672C%u6784%u6210%u5143%u7D20%u53EF%u53C2%u770B%u4E0A%u56FE%uFF1A%0A-%20Initial%20node%20%26%20activity%20final%0A-%20fork%20%26%20join%0A-%20decision%20%26%20merge%0A-%20%u6BCF%u4E00%u4E2A%u5706%u89D2%u7684%u65B9%u6846%u6846%u662F%u4E00%u4E2Aaction%uFF0C%u6240%u6709%u7684%u8FD9%u4E00%u5207%u7EC4%u6210%u4E00%u4E2Aactivity%0A%0A%u5982%u679C%u9700%u8981%u6BCF%u4E00%u4E2Aaction%u53EF%u4EE5%u8F6C%u5316%u6210%u4E00%u4E2A%u5B50%u6D3B%u52A8%28sub%20activity%29%u3002%u7136%u540E%u5728%u4E3B%u56FE%u4E2D%u7528%u4E00%u4E2A%u53C9%u5B50%28rake%29%u8868%u793A%u3002%0A%21%5BAlt%20text%5D%28./1469861910016.png%29%0A%0A%23%23%23When%20to%20Use%20Activity%20Diagrams%0A%3EThe%20great%20strength%20of%20activity%20diagrams%20lies%20in%20the%20fact%20that%20they%20support%20and%20encourage%20parallel%20behavior.%20%0A%0A%u4E0D%u8FC7%u5728%u8FD9%u4E00%u7AE0%u8282%u4E2D%uFF0CFowler%u5927%u5E08%u8FD9%u91CC%u6709%u4E00%u6BB5%u8BDD%u9887%u4E3A%u8010%u4EBA%u5BFB%u5473%uFF1A%0A%3EIn%20principle%2C%20you%20can%20take%20advantages%20of%20the%20forks%20and%20joins%20to%20describe%20parallel%20algorithms%20for%20concurrent%20programs.%20Although%20I%20don%27t%20travel%20in%20concurrent%20circles%20that%20much%2C%20I%20haven%27t%20seen%20much%20evidence%20of%20people%20using%20them%20there.%20%0A%3EI%20think%20the%20reason%20is%20that%20**most%20of%20the%20complexity%20of%20concurrent%20programming%20is%20in%20avoiding%0Acontention%20on%20data%2C%20and%20activity%20diagrams%20don%27t%20help%20much%20with%20that**.%0A%0A%u5E76%u6CA1%u6709%u5F88%u591A%u4EBA%u6216%u8005%u6709%u5F88%u5F3A%u7684%u7406%u7531%u4F7F%u7528%u6D3B%u52A8%u56FE%u6765%u63CF%u8FF0%u5E76%u884C%u7ED3%u6784%uFF0C%u539F%u56E0%u662F%u6D3B%u52A8%u56FE%u5E76%u4E0D%u80FD%u5F88%u597D%u7684%u63CF%u8FF0%u5BF9%u8D44%u6E90%u7684%u4E89%u593A%28contention%29%u3002%0A%23%23%23%u9AD8%u7EA7%u7528%u6CD5%0A%23%23%23%23Partitions%0A%u901A%u8FC7%u6CF3%u9053%u56FE%u6765%u9610%u660Eactions%u90FD%u7531%u54EA%u5199object%u6765%u5B8C%u6210%u7684%u3002%u8FD9%u4E2A%u5BF9%u9610%u8FF0%u6D41%u7A0B%u7684%u65F6%u5019%u6CA1%u4EC0%u4E48%u7528%uFF0C%u4F46%u662F%u5728business%20process%20modeling%u7684%u65F6%u5019%u6BD4%u8F83%u6709%u7528%uFF0C%u53EF%u4EE5%u6E05%u695A%u7684%u8868%u660E%uFF0C%u6BCF%u4E2A%u90E8%u95E8%u6216%u8005%u89D2%u8272%u9700%u8981%u505A%u54EA%u4E9B%u4E8B%u60C5%u3002%u5178%u578B%u7684partitions%u5982%u4E0B%u56FE%0A%21%5BAlt%20text%5D%28./1469862941546.png%29%0A%0A%23%23%23%23Signals%0A%u8FD9%u4E2A%u5728%u63CF%u8FF0%u6D41%u7A0B%u7684%u65F6%u5019%u6BD4%u8F83%u6709%u7528%u3002%u4ED6%u63D0%u4F9B%u4E86%u4E00%u79CD%u6D3B%u52A8%u8D77%u70B9%u7684%u63CF%u8FF0%u3002%u6BD4%u65B9%uFF0C%u7CFB%u7EDF%u54CD%u5E94%u4E00%u4E2A%u5916%u90E8%u4E8B%u4EF6%uFF0C%u6765%u5F00%u59CB%u4E00%u4E2Aactivity%u3002%u4E0B%u9762%u662F%u4F8B%u5B50%0A%21%5BAlt%20text%5D%28./1469863153757.png%29%0A%u4F8B%u5B50%u91CC%u9762%u5305%u542B%u4E86%uFF1A%0A-%20send%20signal%0A-%20accept%20signal%0A-%20time%20signal%0A%23%23%23%23Tokens%0A%u8FD9%u4E2A%u6309%u7167Fowler%u5927%u5E08%u7684%u8BF4%u6CD5%uFF0C%u6709%u4E9BUML%u7684%u5927%u90E8%u5934%u8457%u4F5C%u82B1%u4E86%u5927%u7BC7%u5E45%u7684%u6587%u7AE0%u4ECB%u7ECDtoken%u7684%u4F7F%u7528%u3002%u5728%u590D%u6742%u7CFB%u7EDF%u4E2Dtoken%u53EF%u4EE5%u8BA9%u7CFB%u7EDF%u53EF%u6613%u4E8E%u7406%u89E3%uFF0C%u53EF%u89C6%u5316%u66F4%u597D%u3002%0A%3EYou%20can%20visualize%20the%20tokens%20with%20coins%20or%20counters%20moving%20across%20the%20diagram.%20As%20you%20get%20to%20more%20complicated%20examples%20of%20activity%20diagrams%2C%20tokens%20often%20make%20it%20easier%20to%20visualize%20things.%0A%23%23%23%23Flows%20and%20Edges%0A%u8FD9%u91CC%u63D0%u4F9B%u4E86%u51E0%u79CD%u56FE%u4F8B%uFF0C%u6765%u4E30%u5BCC%u6D3B%u52A8%u56FE%u7684%u753B%u6CD5%u3002%u770B%u4F8B%u5B50%u5C31%u53EF%u4EE5%u4E86%uFF1A%0A%21%5BAlt%20text%5D%28./1469863497950.png%29%0A%u540E%u4E24%u4E2A%u56FE%u63D0%u4F9B%u4E86%u5728action%u4E4B%u95F4%u4F20%u9012object%u7684%u65B9%u6CD5%uFF0C%u4ED6%u4EEC%u7565%u6709%u533A%u522B%u3002%u540E%u9762%u4E13%u95E8%u653E%u4E86%u4E00%u8282%u8BB2pin%u3002pin%u53EF%u4EE5%u505A%u53D8%u6362%28transformations%29%uFF0C%u800Cobject%20node%u505A%u4E0D%u5230%u3002%0A%u770B%u7B2C%u4E09%u5E45%u56FE%uFF0Cobject%20node%u7684%u6846%u6846%u662F%u5C16%u89D2%u77E9%u5F62%uFF0C%u800Caction%u662F%u5706%u89D2%u77E9%u5F62%u3002%0A%23%23%23%23Pins%20and%20Transformations%0A%u770B%u4E00%u4E2Apin%20and%20transformation%u7684%u4F8B%u56FE%uFF1A%0A%21%5BAlt%20text%5D%28./1469863936140.png%29%0A%3E%20Pins%20are%20best%20when%20you%20want%20to%20look%20at%20the%20data%20needed%20and%20produced%20by%20the%20various%20actions.%20%0A%3E%20If%20you%20use%20pins%2C%20it%27s%20safe%20to%20show%20multiple%20flows%20coming%20into%20the%20same%20action.%20The%20pin%20notation%0Areinforces%20the%20implicit%20join%0A%23%23%23%23Expansion%20Regions%0A%u8FD9%u4E2A%u4E3B%u8981%u7528%u6765%u63CF%u8FF0%u4E00%u4E2Aactivity%u7684%u8F93%u51FA%u4F1A%u89E6%u53D1%u82E5%u5E72%u4E2Aactivity%u3002%u770B%u4F8B%u56FE%uFF1A%0A%21%5BAlt%20text%5D%28./1469864217899.png%29%0A%u5982%u679C%u6B64%u82E5%u5E72%u4E2Aactivity%u662F%u540C%u4E00%u79CDactivity%u7684%u8BDD%uFF0C%u53EF%u4EE5%u7528expansion%20region%u7684%u7B80%u5199%u6CD5%uFF1A%0A%21%5BAlt%20text%5D%28./1469864349862.png%29%0A%0A%23%23%23%23Flow%20Final%0AFlow%20Final%u63D0%u4F9B%u4E86%u63D0%u524D%u7ED3%u675F%u4E00%u4E2Aactivity%u5206%u652F%u7684%u63CF%u8FF0%u3002%u770B%u4E0B%u9762%u7684%u4F8B%u5B50%uFF0C%u6709%u4E00%u4E2A%u5206%u652F%u5728%u67D0%u4E00%u60C5%u51B5%u4E0B%uFF0C%u76F4%u63A5%u7ED3%u675F%u4E86%u3002%0A%21%5BAlt%20text%5D%28./1469867539007.png%29%0A%0A%23%23%23%23Join%20Specifications%0Ajoin%u4E4B%u524D%u7684%u5224%u65AD%0A%21%5BAlt%20text%5D%28./1469867666058.png%29%0A%0A%u603B%u5F97%u770B%u6765%uFF0Cactivity%20diagram%u53EF%u4EE5%u7528%u6765%u753Bflow%20chart%uFF0C%u800C%u4E14%u63D0%u4F9B%u4E86%u4E00%u4E0B%u66F4%u9177%u7684%u529F%u80FD%u3002%0A