﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-淡泊明志、宁静致远-随笔分类-架构设计/设计模式</title><link>http://www.cnitblog.com/houcy/category/6990.html</link><description>A Diamond is just a piece of Coal that did well under Pressure.</description><language>zh-cn</language><lastBuildDate>Tue, 27 Sep 2011 20:28:38 GMT</lastBuildDate><pubDate>Tue, 27 Sep 2011 20:28:38 GMT</pubDate><ttl>60</ttl><item><title>从自然规律到复杂数字系统</title><link>http://www.cnitblog.com/houcy/archive/2011/02/26/72879.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Sat, 26 Feb 2011 02:34:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2011/02/26/72879.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/72879.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2011/02/26/72879.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/72879.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/72879.html</trackback:ping><description><![CDATA[<p>下图揭示了复杂的模拟和数字系统是如何从自然规律出发，进行层层抽象，运用物理学、电子学和计算机学的知识，到最终我们使用的平板电脑、智能手机、电子相册等。<br><br><img border=0 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/abstraction.png" width=532 height=584></p>
<img src ="http://www.cnitblog.com/houcy/aggbug/72879.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2011-02-26 10:34 <a href="http://www.cnitblog.com/houcy/archive/2011/02/26/72879.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Pattern---Visitor</title><link>http://www.cnitblog.com/houcy/archive/2010/08/07/67934.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 06 Aug 2010 16:43:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2010/08/07/67934.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/67934.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2010/08/07/67934.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/67934.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/67934.html</trackback:ping><description><![CDATA[&nbsp;意图：<br>表示一个作用于某对象结构中的各元素的操作，在不改变对象结构的前提下，可以很方便地添加新的操作。<br><br>点评：<br>1。该模式诞生的理由是设计类结构时考虑到了以后也许要添加新的操作，因此事先诸葛亮一把，先预留个接口accept( Visitor &amp; v)，以后可以方便地添加新的操作了。符合开闭原则：以后不用修改类对象结构，直接扩展Visitor类即可实现新增操作。<br>2。该模式用到了double-dispatch，说白了就是有两个虚函数，一个在对象结构中，叫做accept，另一个在Visitor中，叫做visit。有两个虚函数就说明了在运行时刻需要确定两次才能知道到底是哪个函数作用在哪个对象上，先确定对象，再确定visitor，可以想象一个二维平面，横轴是特化的对象，纵轴是具体的visitor，纵横交点就是运行时刻确定的具体的操作。<br><br>结构图：<br><img height=566 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/ob.JPG" width=737 border=0><br><br><br>举例：<br>【Context】网站的访问者有游客、一般注册用户、高级注册用户（比如付费用户）和系统管理员。不同的访问者应该看到不同的版块页面，因此当访问者访问网站时需要进行权限检查，当然了，以后还可能进行针对访问者的别的检查，比如访问session是否过期，如未注册者只允许浏览一分钟页面，一般注册者一天只能访问两个小时。<br>【分析】<br>使用CVA分析法，Commonality不变的地方是网站有四类访问者，这些访问者的角色是确定的。变化点Variability是针对访问者的操作，如权限检查、会话Session检查、xx检查。设计模式中的Visitor模式很好地满足此种需求。<br><br>系统的活动场景说明：<br>1.用户输入用户名和密码，点击登录按钮<br>2.页面发送http请求到服务器<br>3.服务器容器的doMethod方法中获取客户请求参数，即用户名和密码<br>4.查询数据库，验证用户名和密码是否合法，并生成对应的访问者对象。<br>5.对于合法的访问者，根据角色设置可浏览的版块页面。<br><br>本文不打算实现一个页面和服务器端代码，使用JSP页面和Servlet很容易实现一个客户端和服务器端的交互，但是本文关注于设计模式的讲解，将从上述活动场景的第4步和第5步进行设计，假设已经验证了用户的合法性，并假设生成一个普通用户和一个高级用户对象。<br><br>【设计】<br>系统中出现的设计类：<br>&nbsp;&nbsp;&nbsp;网站访问者们：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User类、Unregister类、PlainRegister类、AdvancedRegister类、Administrator类<br>&nbsp;&nbsp;&nbsp;网站访问者操作类：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Visitor类、PermittionCheckVisitor类<br>&nbsp;&nbsp;&nbsp;版块类：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Board类<br><br>系统的静态类结构图：<br><img height=456 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/class.jpg" width=1007 border=0><br><br>扩展思考：<br>User和Board之间的关系为：各个版块需要根据User的角色(普通游客、一般用户、高级用户、管理员）显现不同的版块，而四种角色可以相互转变，比如普通游客在线注册了即成为一个普通用户，此时可浏览的版块数量需要变化；一般用户由于付费申请成为了高级用户，可以浏览的版块也要变化；一般用户由于注销了变成普通游客，可浏览的版块也要变化。如此种种变化都是易因为访问者角色的变化引起，因此可以把User设计成为状态模式，四种角色对应四种状态，状态变迁中改变可浏览的版块；也可把User和Board设计成Observer模式，当User角色变化时，调用notify方法通知可浏览的Board们改变显示状态。<br><br>复合模式：<br>关于模式的模式即为复合模式，也可认为是模式的组合，把GoF的23种模式视为元模式，元模式间的组合即成为组合模式。比如一个对象是多个模式的公共元素，此时即为复合模式。<br>上述的User对象是Visitor模式和States模式或Observer模式的公共元素，此时可以视为复合模式。<br>
<img src ="http://www.cnitblog.com/houcy/aggbug/67934.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2010-08-07 00:43 <a href="http://www.cnitblog.com/houcy/archive/2010/08/07/67934.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式随想</title><link>http://www.cnitblog.com/houcy/archive/2010/08/04/67896.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Wed, 04 Aug 2010 05:05:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2010/08/04/67896.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/67896.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2010/08/04/67896.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/67896.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/67896.html</trackback:ping><description><![CDATA[<p>1。应用设计模式时，先考虑当前面临的设计问题是什么，再考虑与之有类似设计问题的GoF模式，继而用相应的设计模式解决问题即可。这就需要在学习设计模式时理解并记住模式的起因由来，是因何种问题才有的对应设计模式。在运行设计模式时，首先应该考虑的是Problem Pattern，继而才有对应的Design Pattern。<br><img height=314 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/problem.JPG" width=862 border=0><br><br><br>2。 从client的角度体会设计模式的美<br>从设计模式使用者的角度来体会模式带来的美感和快感，体会OO的封装、抽象、面向接口编程等机制<br><img height=141 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/look.JPG" width=259 border=0><br><br>3。设计模式周期表<br>用模式在GoF的《设计模式》书中出现的页数作为元素的数字标识，用模式的英文单词首字母作为元素名。简直就是山寨版的化学元素周期表。<br><br><img height=221 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/cycle.JPG" width=432 border=0><br><br><br>4。<br>Observer是一对多的映射，Command是一对一的映射<br>Observer是对数据的变化作出响应，Command是对行为的变化作出响应<br>Observer把数据抽象成subject类，如price, temperature, pressure, data, time等，对外提供获取数据状态的接口；Command把行为封装成Command类，比如openCommand, saveCommand,&nbsp;drawCommand, helpCommand 等。<br></p>
Strategy模式是对core算法进行替换，类似插件，可以轻易替换。<br>Decorator模式是对已有的算法进行包装，提供额外的算法，并不改变已有的基本行为，只是提供可选的新行为。<br><br>Bridge模式把属性抽象和具体行为分离<br>Visitor提供了扩展新函数的接口accept( visitor &amp; v)<br>
<img src ="http://www.cnitblog.com/houcy/aggbug/67896.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2010-08-04 13:05 <a href="http://www.cnitblog.com/houcy/archive/2010/08/04/67896.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Pattern --- Observer</title><link>http://www.cnitblog.com/houcy/archive/2010/08/01/67841.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Sun, 01 Aug 2010 12:29:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2010/08/01/67841.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/67841.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2010/08/01/67841.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/67841.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/67841.html</trackback:ping><description><![CDATA[<p>Intent:<br>&nbsp;&nbsp;&nbsp; Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.<br><br>Examples:<br>&nbsp;&nbsp; auctor, bidders and the bid<br>&nbsp;&nbsp; soccer players, referee and the soccer<br>&nbsp;&nbsp; temperature/pressure and the monitors<br>&nbsp;&nbsp; data and the views<br><br>Structure:<br><img height=264 src="http://www.cnitblog.com/images/cnitblog_com/houcy/Observer2.jpg" width=696 border=0><br><br>示例：<br>温度和压力监测器需要实时更新数据通知显示器，显示器是电脑上的GUI图形窗口，和现场液晶大屏幕。压力和温度就是Subject，电脑和大屏幕是Observer。<br><img height=460 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/observer.JPG" width=585 border=0><br><br>C++ Code:<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">#</span><span style="COLOR: #008000">ifndef&nbsp;SUBJECT_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">define&nbsp;SUBJECT_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;&lt;vector&gt;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;"Observer.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">using&nbsp;namespace&nbsp;std;<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>typedef&nbsp;int&nbsp;state;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Subject<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;public:<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subject()&nbsp;{}<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Subject()&nbsp;{}<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;attach(Observer&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;observer)&nbsp;{<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_observers.push_back(observer);<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;notify()&nbsp;{<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;Observer&nbsp;</span><span style="COLOR: #000000">*&gt;</span><span style="COLOR: #000000">::const_iterator&nbsp;it;<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(it&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;m_observers.begin();&nbsp;it&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;m_observers.end();&nbsp;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">it)<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">it)</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Update(this);<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual&nbsp;void&nbsp;stateChanged(state&nbsp;s)&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;0;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual&nbsp;void&nbsp;getState()</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0;<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;private:<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">Observer&nbsp;</span><span style="COLOR: #000000">*&gt;</span><span style="COLOR: #000000">&nbsp;m_observers;<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>};<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span></div>
<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">#</span><span style="COLOR: #008000">ifndef&nbsp;TEMPERATURE_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">define&nbsp;TEMPERATURE_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;&lt;iostream&gt;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;"Subject.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">using&nbsp;namespace&nbsp;std;<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Temperature&nbsp;:&nbsp;public&nbsp;Subject<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;public:<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Temperature(state&nbsp;s</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0)&nbsp;{m_s&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;s;}<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Temperature()&nbsp;{}<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;stateChanged(state&nbsp;s)&nbsp;{<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Temperature&nbsp;changed</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_s&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;s;<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notify();<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;getState()&nbsp;{<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getTemperature();<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;getTemperature()&nbsp;{<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Current&nbsp;temperature&nbsp;is&nbsp;</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">m_s</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">&#176;</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;private:<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state&nbsp;m_s;<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>};<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">30</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">#</span><span style="COLOR: #008000">ifndef&nbsp;OBSERVER_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">define&nbsp;OBSERVER_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Subject;<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Observer<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;public:<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Observer()&nbsp;{}<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Observer()&nbsp;{}<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual&nbsp;void&nbsp;Update(Subject&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;subject)&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;0;<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>};<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span></div>
<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #008000">#</span><span style="COLOR: #008000">ifndef&nbsp;ENVIRONMENTWINDOW_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">define&nbsp;ENVIRONMENTWINDOW_H</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;&lt;iostream&gt;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;"Observer.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Subject;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;EnvironmentWindow&nbsp;:&nbsp;public&nbsp;Observer<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;public:<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EnvironmentWindow()&nbsp;{}<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">EnvironmentWindow()&nbsp;{}<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void&nbsp;Update(Subject&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;subject)<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subject</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">getState();<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>};<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">endif</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">21</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000">include&nbsp;"Subject.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">17</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;"Observer.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">18</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;"Temperature.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">19</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>#</span><span style="COLOR: #008000">include&nbsp;"EnvironmentWindow.h"</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">20</span><span style="COLOR: #008000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">argv[])<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Subject&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;temp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;new&nbsp;Temperature();<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Observer&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;observer&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;new&nbsp;EnvironmentWindow();<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">attach(observer);<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">stateChanged(</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">stateChanged(</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">stateChanged(</span><span style="COLOR: #000000">35</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">PAUSE</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;EXIT_SUCCESS;<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top>}<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cnitblog.com/houcy/aggbug/67841.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2010-08-01 20:29 <a href="http://www.cnitblog.com/houcy/archive/2010/08/01/67841.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>主流计算机语言家谱</title><link>http://www.cnitblog.com/houcy/archive/2010/04/09/65163.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 09 Apr 2010 07:49:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2010/04/09/65163.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/65163.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2010/04/09/65163.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/65163.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/65163.html</trackback:ping><description><![CDATA[<p><img height=768 alt="" src="http://www.cnitblog.com/images/cnitblog_com/houcy/lang.JPG" width=597 border=0></p>
<img src ="http://www.cnitblog.com/houcy/aggbug/65163.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2010-04-09 15:49 <a href="http://www.cnitblog.com/houcy/archive/2010/04/09/65163.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Deployment Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62569.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:13:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62569.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62569.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62569.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62569.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62569.html</trackback:ping><description><![CDATA[Deployment Diagrams<br><span class=body-text>A deployment diagram models the run-time architecture of a system. It shows the configuration of the hardware elements (nodes) and shows how software elements and artifacts are mapped onto those nodes.<br></span>
<p class=body-text-bld>Node<br><span class=body-text>A Node is either a hardware or software element. It is shown as a three-dimensional box shape, as shown below.</span> </p>
<p class=body-text><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/dd02.GIF" width=130> </p>
<p><span class=body-text-bld>Node Instance</span><br><span class=body-text>A node instance can be shown on a diagram. An instance can be distinguished from a node by the fact that its name is underlined and has a colon before its base node type. An instance may or may not have a name before the colon. The following diagram shows a named instance of a computer.</span> </p>
<p class=body-text><img height=105 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/dd03.GIF" width=140> </p>
<p><span class=body-text-bld>Node Stereotypes</span><br><span class=body-text>A number of standard stereotypes are provided for nodes, namely &#171;cdrom&#187;, &#171;cd-rom&#187;, &#171;computer&#187;, &#171;disk array&#187;, &#171;pc&#187;, &#171;pc client&#187;, &#171;pc server&#187;, &#171;secure&#187;, &#171;server&#187;, &#171;storage&#187;, &#171;unix server&#187;, &#171;user pc&#187;. These will display an appropriate icon in the top right corner of the node symbol</span> </p>
<p class=body-text><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/dd04.GIF" width=582> </p>
<p><span class=body-text-bld>Artifact</span><br><span class=body-text>An artifact is a product of the <a href="http://www.sparxsystems.com/platforms/software_development.html">software development</a> process. That may include process models (e.g. use case models, design models etc), source files, executables, design documents, test reports, prototypes, user manuals, etc.</span> </p>
<p><span class=body-text>An artifact is denoted by a rectangle showing the artifact name, the &#171;artifact&#187; keyword and a document icon, as shown below.</span><br></p>
<p class=body-text><img height=100 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/dd05.GIF" width=130> </p>
<p><span class=body-text-bld>Association</span><br><span class=body-text>In the context of a deployment diagram, an association represents a communication path between nodes. The following diagram shows a deployment diagram for a network, depicting network protocols as stereotypes, and multiplicities at the association ends.</span> </p>
<p class=body-text><img height=363 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/dd06.GIF" width=320> </p>
<p class=body-text></p>
<p><span class=body-text-bld>Node as Container</span><br><span class=body-text>A node can contain other elements, such as components or artifacts. The following diagram shows a deployment diagram for part of an embedded system, depicting an executable artifact as being contained by the motherboard node.</span> </p>
<p class=body-text><img height=181 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/dd01.GIF" width=370> </p>
<img src ="http://www.cnitblog.com/houcy/aggbug/62569.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:13 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62569.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Component Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62568.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:12:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62568.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62568.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62568.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62568.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62568.html</trackback:ping><description><![CDATA[Component Diagrams<br><span class=body-text>Component diagrams illustrate the pieces of software, embedded controllers, etc., that will make up a system. A component diagram has a higher level of abstraction than a Class Diagram - usually a component is implemented by one or more classes (or objects) at runtime. They are building blocks so a component can eventually encompass a large portion of a system.</span>
<p class=body-text-bld><span class=body-text><img height=440 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/cd03.GIF" width=447></span> </p>
<p class=body-text-bld><span class=body-text>The diagram above demonstrates some components and their inter-relationships. Assembly connectors "link" the provided interfaces supplied by "Product" and "Customer" to the required interfaces specified by "Order". A dependency relationship maps a customer's associated account details to the required interface; "Payment", indicated by "Order".</span> </p>
<p class=body-text>Components are similar in practice to package diagrams, as they define boundaries and are used to group elements into logical structures. The difference between package diagrams and component diagrams is that Component Diagrams offer a more semantically rich grouping mechanism. With component diagrams all of the model elements are private, whereas package diagrams only display public items. </p>
<p class=body-text-bld>Representing Components<br><span class=body-text>Components are represented as a rectangular classifier with the keyword &#171;component&#187;; optionally the component may be displayed as a rectangle with a component icon in the right-hand upper corner.</span> </p>
<p class=body-text><img height=110 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/cd02.GIF" width=307> </p>
<p><span class=body-text-bld>Assembly Connector </span><br><span class=body-text>The assembly connector bridges a component&#8217;s required interface (Component1) with the provided interface of another component (Component2); this allows one component to provide the services that another component requires.</span> </p>
<p class=body-text><img height=110 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CD04.GIF" width=377> </p>
<p><span class=body-text-bld>Components with Ports </span><br><span class=body-text>Using Ports with component diagrams allows for a service or behavior to be specified to its environment as well as a service or behavior that a component requires. Ports may specify inputs and outputs as they can operate bi-directionally. The following diagram details a component with a port for online services along with two provided interfaces order entry and tracking as well as a required interface payment.</span> </p>
<p class=body-text><img height=199 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/cd01.GIF" width=311> </p>
<img src ="http://www.cnitblog.com/houcy/aggbug/62568.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:12 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62568.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Class Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62567.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:11:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62567.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62567.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62567.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62567.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62567.html</trackback:ping><description><![CDATA[Class Diagrams<br><span class=body-text>The class diagram shows the building blocks of any object-orientated system. Class diagrams depict a static view of the model, or part of the model, describing what attributes and behavior it has rather than detailing the methods for achieving operations. Class diagrams are most useful in illustrating relationships between classes and interfaces. Generalizations, aggregations, and associations are all valuable in reflecting inheritance, composition or usage, and connections respectively.</span><span class=body-text><br><br>The diagram below illustrates aggregation relationships between classes. The lighter aggregation indicates that the class "Account" uses AddressBook, but does not necessarily contain an instance of it. The strong, composite aggregations by the other connectors indicate ownership or containment of the source classes by the target classes, for example Contact and ContactGroup values will be contained in AddressBook.</span>
<p class=body-text-bld><img height=459 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/cl01.png" width=651> </p>
<p class=body-text-bld>Classes<br><span class=body-text>A class is an element that defines the attributes and behaviors that an object is able to generate. The behavior is described by the possible messages the class is able to understand, along with operations that are appropriate for each message. Classes may also have definitions of constraints, tagged values and stereotypes.</span> </p>
<p class=body-text-bld>Class Notation<br><span class=body-text>Classes are represented by rectangles which show the name of the class and optionally the name of the operations and attributes. Compartments are used to divide the class name, attributes and operations.<br><br>In the diagram below the class contains the class name in the topmost compartment, the next compartment details the attributes, with the "center" attribute showing initial values. The final compartment shows the operations setWidth, setLength and setPosition and their parameters. The notation that precedes the attribute, or operation name, indicates the visibility of the element: if the + symbol is used, the attribute, or operation, has a public level of visibility; if a - symbol is used, the attribute, or operation, is private. In addition the # symbol allows an operation, or attribute, to be defined as protected, while the ~ symbol indicates package visibility.</span> </p>
<p class=body-text><img height=206 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL02.GIF" width=211> </p>
<p><span class=body-text-bld>Interfaces</span><br><span class=body-text>An interface is a specification of behavior that implementers agree to meet; it is a contract. By realizing an interface, classes are guaranteed to support a required behavior, which allows the system to treat non-related elements in the same way &#8211; that is, through the common interface.</span> </p>
<p class=body-text><img height=315 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL03.GIF" width=204> </p>
<p><span class=body-text>Interfaces may be drawn in a similar style to a class, with operations specified, as shown below. They may also be drawn as a circle with no explicit operations detailed. When drawn as a circle, realization links to the circle form of notation are drawn without target arrows.</span> </p>
<p class=body-text><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL04.GIF" width=261> </p>
<p><span class=body-text-bld>Tables</span><br><span class=body-text>Although not a part of the base UML, a table is an example of what can be done with stereotypes. It is drawn with a small table icon in the upper right corner. Table attributes are stereotyped &#171;column&#187;. Most tables will have a primary key, being one or more fields that form a unique combination used to access the table, plus a primary key operation which is stereotyped &#171;PK&#187;. Some tables will have one or more foreign keys, being one or more fields that together map onto a primary key in a related table, plus a foreign key operation which is stereotyped &#171;FK&#187;.</span> </p>
<p class=body-text><img height=161 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL05.GIF" width=218> </p>
<p><span class=body-text-bld>Associations</span><br><span class=body-text>An association implies two model elements have a relationship - usually implemented as an instance variable in one class. This connector may include named roles at each end, cardinality, direction and constraints. Association is the general relationship type between elements. For more than two elements, a diamond representation toolbox element can be used as well. When code is generated for class diagrams, named association ends become instance variables in the target class. So, for the example below, "playsFor" will become an instance variable in the "Player" class.</span> </p>
<p class=body-text><img height=121 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL06.GIF" width=351> </p>
<p><span class=body-text-bld>Generalizations</span><br><span class=body-text>A generalization is used to indicate inheritance. Drawn from the specific classifier to a general classifier, the generalize implication is that the source inherits the target's characteristics. The following diagram shows a parent class generalizing a child class. Implicitly, an instantiated object of the Circle class will have attributes x_position, y_position and radius and a method display(). Note that the class "Shape" is abstract, shown by the name being italicized.</span> </p>
<p class=body-text><img height=138 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL07.GIF" width=346> </p>
<p class=body-text>The following diagram shows an equivalent view of the same information. </p>
<p class=body-text><img height=180 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL08.GIF" width=157> </p>
<p><span class=body-text-bld>Aggregations</span><br><span class=body-text>Aggregations are used to depict elements which are made up of smaller components. Aggregation relationships are shown by a white diamond-shaped arrowhead pointing towards the target or parent class.<br><br>A stronger form of aggregation - a composite aggregation - is shown by a black diamond-shaped arrowhead and is used where components can be included in a maximum of one composition at a time. If the parent of a composite aggregation is deleted, usually all of its parts are deleted with it; however a part can be individually removed from a composition without having to delete the entire composition. Compositions are transitive, asymmetric relationships and can be recursive. <br><br>The following diagram illustrates the difference between weak and strong aggregations. An address book is made up of a multiplicity of contacts and contact groups. A contact group is a virtual grouping of contacts; a contact may be included in more than one contact group. If you delete an address book, all the contacts and contact groups will be deleted too; if you delete a contact group, no contacts will be deleted. </span></p>
<p class=body-text><img height=263 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL09.GIF" width=314> </p>
<p><span class=body-text-bld>Association Classes</span><br><span class=body-text>An association class is a construct that allows an association connection to have operations and attributes. The following example shows that there is more to allocating an employee to a project than making a simple association link between the two classes: the role the employee takes up on the project is a complex entity in its own right and contains detail that does not belong in the employee or project class. For example, an employee may be working on several projects at the same time and have different job titles and security levels on each.</span> </p>
<p class=body-text><img height=225 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL10.GIF" width=396> </p>
<p><span class=body-text-bld>Dependencies</span><br><span class=body-text>A dependency is used to model a wide range of dependent relationships between model elements. It would normally be used early in the design process where it is known that there is some kind of link between two elements, but it is too early to know exactly what the relationship is. Later in the design process, dependencies will be stereotyped (stereotypes available include &#171;instantiate&#187;, &#171;trace&#187;, &#171;import&#187;, and others), or replaced with a more specific type of connector.</span> </p>
<p><span class=body-text-bld>Traces</span><br><span class=body-text>The trace relationship is a specialization of a dependency, linking model elements or sets of elements that represent the same idea across models. Traces are often used to track requirements and model changes. As changes can occur in both directions, the order of this dependency is usually ignored. The relationship's properties can specify the trace mapping, but the trace is usually bi-directional, informal and rarely computable.</span> </p>
<p><span class=body-text-bld>Realizations</span><br><span class=body-text>The source object implements or realizes the destination. Realizations are used to express traceability and completeness in the model - a business process or requirement is realized by one or more use cases, which are in turn realized by some classes, which in turn are realized by a component, etc. Mapping requirements, classes, etc. across the design of your system, up through the levels of modeling abstraction, ensures the big picture of your system remembers and reflects all the little pictures and details that constrain and define it. A realization is shown as a dashed line with a solid arrowhead.</span> </p>
<p class=body-text><img height=315 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL03.GIF" width=204> </p>
<p><span class=body-text-bld>Nestings</span><br><span class=body-text>A nesting is connector that shows the source element is nested within the target element. The following diagram shows the definition of an inner class, although in EA it is more usual to show them by their position in the project view hierarchy.</span> </p>
<p class=body-text><img height=120 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/CL12.GIF" width=340> </p>
<img src ="http://www.cnitblog.com/houcy/aggbug/62567.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:11 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62567.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Package Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62566.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:10:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62566.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62566.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62566.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62566.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62566.html</trackback:ping><description><![CDATA[Package Diagrams<br><span class=body-text>Package diagrams are used to reflect the organization of packages and their elements. When used to represent class elements, package diagrams provide a visualization of the namespaces. The most common use for package diagrams is to organize use case diagrams and class diagrams, although the use of package diagrams is not limited to these UML elements.<br><br>The following is an example of a package diagram.</span>
<p class=body-text-bld><img height=419 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/pd01.gif" width=720> </p>
<p class=body-text>Elements contained in a package share the same namespace. Therefore, the elements contained in a specific namespace must have unique names. </p>
<p class=body-text>Packages can be built to represent either physical or logical relationships. When choosing to include classes in specific packages, it is useful to assign the classes with the same inheritance hierarchy to the same package. There is also a strong argument for including classes that are related via composition, and classes that collaborate with them, in the same package. </p>
<p class=body-text><img height=130 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/pd02.GIF" width=170> </p>
<p><span class=body-text>Packages are represented in UML 2.1 as folders and contain the elements that share a namespace; all elements within a package must be identifiable, and so have a unique name or type. The package must show the package name and can optionally show the elements within the package in extra compartments.</span> </p>
<p><span class=body-text-bld>Package Merge</span><br><span class=body-text>A &#171;merge&#187; connector between two packages defines an implicit generalization between elements in the source package, and elements with the same name in the target package. The source element definitions are expanded to include the element definitions contained in the target. The target element definitions are unaffected, as are the definitions of source package elements that don't match names with any element in the target package.</span> </p>
<p><span class=body-text-bld>Package Import </span><br><span class=body-text>The &#171;import&#187; connector indicates that the elements within the target package, which in this example is a single class, use unqualified names when being referred to from the source package. The source package's namespace gains access to the target classes; the target's namespace is not affected.</span> </p>
<p><span class=body-text-bld>Nesting Connectors</span><br><span class=body-text>The nesting connector between the target package and source packages shows that the source package is fully contained in the target package.</span> </p>
<img src ="http://www.cnitblog.com/houcy/aggbug/62566.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:10 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62566.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>State Machine Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62565.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:09:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62565.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62565.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62565.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62565.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62565.html</trackback:ping><description><![CDATA[State Machine Diagrams<br><span class=body-text>A state machine diagram models the behaviour of a single object, specifying the sequence of events that an object goes through during its lifetime in response to events.</span><span class=body-text><br><br>As an example, the following state machine diagram shows the states that a door goes through during its lifetime.</span>
<p class=body-text-bld><img height=243 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm01.GIF" width=517> </p>
<p><span class=body-text>The door can be in one of three states: "Opened", "Closed" or "Locked". It can respond to the events Open, Close, Lock and Unlock. Notice that not all events are valid in all states; for example, if a door is opened, you cannot lock it until you close it. Also notice that a state transition can have a guard condition attached: if the door is Opened, it can only respond to the Close event if the condition doorWay-&gt;isEmpty is fulfilled. The syntax and conventions used in state machine diagrams will be discussed in full in the following sections.</span> </p>
<p class=body-text-bld>States </p>
<p class=body-text>A state is denoted by a round-cornered rectangle with the name of the state written inside it. </p>
<p class=body-text><img height=110 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm02.GIF" width=160> </p>
<p><span class=body-text-bld>Initial and Final States</span><br><span class=body-text>The initial state is denoted by a filled black circle and may be labeled with a name. The final state is denoted by a circle with a dot inside and may also be labeled with a name.</span> </p>
<p class=body-text><img height=118 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm03.GIF" width=333> </p>
<p class=body-text-bld>Transitions<br><span class=body-text>Transitions from one state to the next are denoted by lines with arrowheads. A transition may have a trigger, a guard and an effect, as below.</span> </p>
<p class=body-text><img height=111 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm04.GIF" width=420> </p>
<p class=body-text>"Trigger" is the cause of the transition, which could be a signal, an event, a change in some condition, or the passage of time. "Guard" is a condition which must be true in order for the trigger to cause the transition. "Effect" is an action which will be invoked directly on the object that owns the state machine as a result of the transition. </p>
<p><span class=body-text-bld>State Actions</span><br><span class=body-text>In the transition example above, an effect was associated with the transition. If the target state had many transitions arriving at it, and each transition had the same effect associated with it, it would be better to associate the effect with the target state rather than the transitions. This can be done by defining an entry action for the state. The diagram below shows a state with an entry action and an exit action.</span> </p>
<p class=body-text><img height=124 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm05.GIF" width=203> </p>
<p class=body-text>It is also possible to define actions that occur on events, or actions that always occur. It is possible to define any number of actions of each type. </p>
<p><span class=body-text-bld>Self-Transitions</span><br><span class=body-text>A state can have a transition that returns to itself, as in the following diagram. This is most useful when an effect is associated with the transition.</span> </p>
<p class=body-text><img height=154 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm06.GIF" width=171> </p>
<p><span class=body-text-bld>Compound States</span><br><span class=body-text>A state machine diagram may include sub-machine diagrams, as in the example below.</span> </p>
<p class=body-text><img height=519 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm07.GIF" width=480> </p>
<p class=body-text>The alternative way to show the same information is as follows. </p>
<p class=body-text><img height=357 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm08.GIF" width=350> </p>
<p class=body-text>The notation in the above version indicates that the details of the Check PIN sub-machine are shown in a separate diagram. </p>
<p><span class=body-text-bld>Entry Point</span><br><span class=body-text>Sometimes you won&#8217;t want to enter a sub-machine at the normal initial state. For example, in the following sub-machine it would be normal to begin in the "Initializing" state, but if for some reason it wasn&#8217;t necessary to perform the initialization, it would be possible to begin in the "Ready" state by transitioning to the named entry point.</span> </p>
<p class=body-text><img height=244 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm09.GIF" width=336> </p>
<p class=body-text>The following diagram shows the state machine one level up. </p>
<p class=body-text><img height=199 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm10.GIF" width=329> </p>
<p><span class=body-text-bld>Exit Point</span><br><span class=body-text>In a similar manner to entry points, it is possible to have named alternative exit points. The following diagram gives an example where the state executed after the main processing state depends on which route is used to transition out of the state.</span> </p>
<p class=body-text><img height=265 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm11.GIF" width=575> </p>
<p><span class=body-text-bld>Choice Pseudo-State</span><br><span class=body-text>A choice pseudo-state is shown as a diamond with one transition arriving and two or more transitions leaving. The following diagram shows that whichever state is arrived at, after the choice pseudo-state, is dependent on the message format selected during execution of the previous state.</span> </p>
<p class=body-text><img height=276 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm12.GIF" width=419> </p>
<p><span class=body-text-bld>Junction Pseudo-State</span><br><span class=body-text>Junction pseudo-states are used to chain together multiple transitions. A single junction can have one or more incoming, and one or more outgoing, transitions; a guard can be applied to each transition. Junctions are semantic-free. A junction which splits an incoming transition into multiple outgoing transitions realizes a static conditional branch, as opposed to a choice pseudo-state which realizes a dynamic conditional branch.</span> </p>
<p class=body-text><img height=342 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm13.GIF" width=458> </p>
<p><span class=body-text-bld>Terminate Pseudo-State</span><br><span class=body-text>Entering a terminate pseudo-state indicates that the lifeline of the state machine has ended. A terminate pseudo-state is notated as a cross.</span> </p>
<p class=body-text><img height=118 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm14.GIF" width=295> </p>
<p><span class=body-text-bld>History States</span><br><span class=body-text>A history state is used to remember the previous state of a state machine when it was interrupted. The following diagram illustrates the use of history states. The example is a state machine belonging to a washing machine.</span> </p>
<p class=body-text><img height=290 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm15.GIF" width=574> </p>
<p class=body-text>In this state machine, when a washing machine is running, it will progress from "Washing" through "Rinsing" to "Spinning". If there is a power cut, the washing machine will stop running and will go to the "Power Off" state. Then when the power is restored, the Running state is entered at the "History State" symbol meaning that it should resume where it last left-off. </p>
<p class=body-text-bld>Concurrent Regions<br><span class=body-text>A state may be divided into regions containing sub-states that exist and execute concurrently. The example below shows that within the state "Applying Brakes", the front and rear brakes will be operating simultaneously and independently. Notice the use of fork and join pseudo-states, rather than choice and merge pseudo-states. These symbols are used to synchronize the concurrent threads.</span> </p>
<p class=body-text><img height=218 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/sm16.GIF" width=445> </p>
<a href="http://www.sparxsystems.com/resources/uml2_tutorial/uml2_statediagram.html">http://www.sparxsystems.com/resources/uml2_tutorial/uml2_statediagram.html</a>
<img src ="http://www.cnitblog.com/houcy/aggbug/62565.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:09 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62565.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Activity Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62564.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:08:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62564.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62564.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62564.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62564.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62564.html</trackback:ping><description><![CDATA[Activity Diagrams<br><span class=body-text>In UML, an activity diagram is used to display the sequence of activities. Activity diagrams show the workflow from a start point to the finish point detailing the many decision paths that exist in the progression of events contained in the activity. They may be used to detail situations where parallel processing may occur in the execution of some activities. Activity diagrams are useful for business modelling where they are used for detailing the processes involved in business activities.<br><br>An Example of an activity diagram is shown below. </span>
<p class=body-text-bld><img height=318 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad03.GIF" width=721> </p>
<p class=body-text>The following sections describe the elements that constitute an activity diagram. </p>
<p class=body-text-bld>Activities<br><span class=body-text>An activity is the specification of a parameterized sequence of behaviour. An activity is shown as a round-cornered rectangle enclosing all the actions, control flows and other elements that make up the activity.</span> </p>
<p class=body-text><img height=161 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad05.GIF" width=343> </p>
<p><span class=body-text-bld>Actions</span><br><span class=body-text>An action represents a single step within an activity. Actions are denoted by round-cornered rectangles.</span> </p>
<p class=body-text><img height=85 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad07.GIF" width=110> </p>
<p><span class=body-text-bld>Action Constraints</span><br><span class=body-text>Constraints can be attached to an action. The following diagram shows an action with local pre- and post-conditions.</span> </p>
<p class=body-text><img height=245 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad01.GIF" width=186> </p>
<p><span class=body-text-bld>Control Flow</span><br><span class=body-text>A control flow shows the flow of control from one action to the next. Its notation is a line with an arrowhead.</span> </p>
<p class=body-text><img height=85 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad06.GIF" width=251> </p>
<p><span class=body-text-bld>Initial Node</span><br><span class=body-text>An initial or start node is depicted by a large black spot, as shown below.</span> </p>
<p class=body-text><img height=85 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad14.GIF" width=185> </p>
<p class=body-text></p>
<p><span class=body-text-bld>Final Node</span><br><span class=body-text>There are two types of final node: activity and flow final nodes. The activity final node is depicted as a circle with a dot inside.</span> </p>
<p class=body-text><img height=85 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad04.GIF" width=192> </p>
<p class=body-text>The flow final node is depicted as a circle with a cross inside. </p>
<p class=body-text><img height=85 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad09.GIF" width=170> </p>
<p class=body-text>The difference between the two node types is that the flow final node denotes the end of a single control flow; the activity final node denotes the end of all control flows within the activity.<br></p>
<p class=body-text><span class=body-text-bld>Objects and Object Flows</span><br>An object flow is a path along which objects or data can pass. An object is shown as a rectangle. </p>
<p class=body-text><img height=100 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad15.GIF" width=130> </p>
<p class=body-text>An object flow is shown as a connector with an arrowhead denoting the direction the object is being passed. </p>
<p class=body-text><img height=100 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad16.GIF" width=340><br></p>
<p class=body-text>An object flow must have an object on at least one of its ends. A shorthand notation for the above diagram would be to use input and output pins. </p>
<p class=body-text><img height=93 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad17.GIF" width=300> </p>
<p class=body-text>A data store is shown as an object with the &#171;datastore&#187; keyword. </p>
<p class=body-text><img height=100 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad18.GIF" width=130> </p>
<p class=body-text><span class=body-text-bld>Decision and Merge Nodes</span><br>Decision nodes and merge nodes have the same notation: a diamond shape. They can both be named. The control flows coming away from a decision node will have guard conditions which will allow control to flow if the guard condition is met. The following diagram shows use of a decision node and a merge node. </p>
<p class=body-text><img height=177 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad08.GIF" width=380> </p>
<p class=body-text><span class=body-text-bld>Fork and Join Nodes</span><br>Forks and joins have the same notation: either a horizontal or vertical bar (the orientation is dependent on whether the control flow is running left to right or top to bottom). They indicate the start and end of concurrent threads of control. The following diagram shows an example of their use. </p>
<p class=body-text><img height=136 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad10.GIF" width=340> </p>
<p class=body-text>A join is different from a merge in that the join synchronizes two inflows and produces a single outflow. The outflow from a join cannot execute until all inflows have been received. A merge passes any control flows straight through it. If two or more inflows are received by a merge symbol, the action pointed to by its outflow is executed two or more times. </p>
<p class=body-text><span class=body-text-bld>Expansion Region</span><br>An expansion region is a structured activity region that executes multiple times. Input and output expansion nodes are drawn as a group of three boxes representing a multiple selection of items. The keyword "iterative", "parallel" or "stream" is shown in the top left corner of the region. </p>
<p><img height=212 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad12.GIF" width=375> </p>
<p class=body-text><span class=body-text-bld>Exception Handlers</span><br>Exception Handlers can be modelled on activity diagrams as in the example below. </p>
<p class=body-text><img height=125 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad11.GIF" width=451> </p>
<p class=body-text><span class=body-text-bld>Interruptible Activity Region</span><br>An interruptible activity region surrounds a group of actions that can be interrupted. In the very simple example below, the "Process Order" action will execute until completion, when it will pass control to the "Close Order" action, unless a "Cancel Request" interrupt is received, which will pass control to the "Cancel Order" action. </p>
<p class=body-text><img height=207 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad13.GIF" width=426> </p>
<p class=body-text><span class=body-text-bld>Partition</span><br>An activity partition is shown as either a horizontal or vertical swimlane. In the following diagram, the partitions are used to separate actions within an activity into those performed by the accounting department and those performed by the customer. </p>
<p class=body-text><img height=303 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/ad19.GIF" width=410> </p>
<a href="http://www.sparxsystems.com/resources/uml2_tutorial/uml2_activitydiagram.html">http://www.sparxsystems.com/resources/uml2_tutorial/uml2_activitydiagram.html</a>
<img src ="http://www.cnitblog.com/houcy/aggbug/62564.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:08 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62564.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sequence Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62563.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:06:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62563.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62563.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62563.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62563.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62563.html</trackback:ping><description><![CDATA[<p>Sequence Diagrams<br><span class=body-text>A sequence diagram is a form of interaction diagram which shows objects as lifelines running down the page, with their interactions over time represented as messages drawn as arrows from the source lifeline to the target lifeline. Sequence diagrams are good at showing which objects communicate with which other objects; and what messages trigger those communications. Sequence diagrams are not intended for showing complex procedural logic.</span> </p>
<p class=body-text-bld>Lifelines<br><span class=body-text>A lifeline represents an individual participant in a sequence diagram. A lifeline will usually have a rectangle containing its object name. If its name is "self", that indicates that the lifeline represents the classifier which owns the sequence diagram.</span> </p>
<p class=body-text-bld><img height=187 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq01.GIF" width=371> </p>
<p class=body-text>Sometimes a sequence diagram will have a lifeline with an actor element symbol at its head. This will usually be the case if the sequence diagram is owned by a use case. Boundary, control and entity elements from robustness diagrams can also own lifelines. </p>
<p class=body-text-bld><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq02.GIF" width=343> </p>
<p class=body-text-bld>Messages<br><span class=body-text>Messages are displayed as arrows. Messages can be complete, lost or found; synchronous or asynchronous; call or signal. In the following diagram, the first message is a synchronous message (denoted by the solid arrowhead) complete with an implicit return message; the second message is asynchronous (denoted by line arrowhead), and the third is the asynchronous return message (denoted by the dashed line).</span> </p>
<p class=body-text-bld><img height=262 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq03.GIF" width=326> </p>
<p class=body-text-bld>Execution Occurrence<br><span class=body-text>A thin rectangle running down the lifeline denotes the execution occurrence, or activation of a focus of control. In the previous diagram, there are three execution occurrences. The first is the source object sending two messages and receiving two replies; the second is the target object receiving a synchronous message and returning a reply; and the third is the target object receiving an asynchronous message and returning a reply.</span> </p>
<p class=body-text-bld>Self Message<br><span class=body-text>A self message can represent a recursive call of an operation, or one method calling another method belonging to the same object. It is shown as creating a nested focus of control in the lifeline&#8217;s execution occurrence.</span> </p>
<p class=body-text><img height=259 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq04.GIF" width=191> </p>
<p class=body-text-bld>Lost and Found Messages<br><span class=body-text>Lost messages are those that are either sent but do not arrive at the intended recipient, or which go to a recipient not shown on the current diagram. Found messages are those that arrive from an unknown sender, or from a sender not shown on the current diagram. They are denoted going to or coming from an endpoint element.</span> </p>
<p class=body-text><img height=233 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq10.GIF" width=229> </p>
<p class=body-text-bld>Lifeline Start and End<br><span class=body-text>A lifeline may be created or destroyed during the timescale represented by a sequence diagram. In the latter case, the lifeline is terminated by a stop symbol, represented as a cross. In the former case, the symbol at the head of the lifeline is shown at a lower level down the page than the symbol of the object that caused the creation. The following diagram shows an object being created and destroyed.</span> </p>
<p class=body-text><img height=232 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq05.GIF" width=363> </p>
<p class=body-text-bld>Duration and Time Constraints<br><span class=body-text>By default, a message is shown as a horizontal line. Since the lifeline represents the passage of time down the screen, when modelling a real-time system, or even a time-bound business process, it can be important to consider the length of time it takes to perform actions. By setting a duration constraint for a message, the message will be shown as a sloping line.</span> </p>
<p class=body-text><img height=350 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq06.GIF" width=363> </p>
<p class=body-text-bld>Combined Fragments<br></p>
<p><span class=body-text>It was stated earlier that sequence diagrams are not intended for showing complex procedural logic. While this is the case, there are a number of mechanisms that do allow for adding a degree of procedural logic to diagrams and which come under the heading of combined fragments. A combined fragment is one or more processing sequence enclosed in a frame and executed under specific named circumstances. The fragments available are:<br></span></p>
<ul class=body-text>
    <li>Alternative fragment (denoted &#8220;alt&#8221;) models if&#8230;then&#8230;else constructs.
    <li>Option fragment (denoted &#8220;opt&#8221;) models switch constructs.
    <li>Break fragment models an alternative sequence of events that is processed instead of the whole of the rest of the diagram.
    <li>Parallel fragment (denoted &#8220;par&#8221;) models concurrent processing.
    <li>Weak sequencing fragment (denoted &#8220;seq&#8221;) encloses a number of sequences for which all the messages must be processed in a preceding segment before the following segment can start, but which does not impose any sequencing within a segment on messages that don&#8217;t share a lifeline.
    <li>Strict sequencing fragment (denoted &#8220;strict&#8221;) encloses a series of messages which must be processed in the given order.
    <li>Negative fragment (denoted &#8220;neg&#8221;) encloses an invalid series of messages.
    <li>Critical fragment encloses a critical section.
    <li>Ignore fragment declares a message or message to be of no interest if it appears in the current context.
    <li>Consider fragment is in effect the opposite of the ignore fragment: any message not included in the consider fragment should be ignored.
    <li>Assertion fragment (denoted &#8220;assert&#8221;) designates that any sequence not shown as an operand of the assertion is invalid.
    <li>Loop fragment encloses a series of messages which are repeated. </li>
</ul>
<p><span class=body-text>The following diagram shows a loop fragment.</span> </p>
<p>&#160;</p>
<p class=body-text><img height=396 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq07.GIF" width=428> </p>
<p class=body-text>There is also an interaction occurrence, which is similar to a combined fragment. An interaction occurrence is a reference to another diagram which has the word "ref" in the top left corner of the frame, and has the name of the referenced diagram shown in the middle of the frame. </p>
<p class=body-text-bld>Gate<br><span class=body-text>A gate is a connection point for connecting a message inside a fragment with a message outside a fragment. EA shows a gate as a small square on a fragment frame. Diagram gates act as off-page connectors for sequence diagrams, representing the source of incoming messages or the target of outgoing messages. The following two diagrams show how they might be used in practice. Note that the gate on the top level diagram is the point at which the message arrowhead touches the reference fragment - there is no need to render it as a box shape.</span> </p>
<p class=body-text><img height=271 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq12.GIF" width=404> </p>
<p class=body-text><img height=236 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq13.GIF" width=385> </p>
<p class=body-text-bld>Part Decomposition<br><span class=body-text>An object can have more than one lifeline coming from it. This allows for inter- and intra-object messages to be displayed on the same diagram.</span> </p>
<p class=body-text><img height=392 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq11.GIF" width=375> </p>
<p class=body-text-bld>State Invariant / Continuations<br><span class=body-text>A state invariant is a constraint placed on a lifeline that must be true at run-time. It is shown as a rectangle with semi-circular ends.</span> </p>
<p class=body-text><img height=211 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/seq09.GIF" width=130> </p>
<p class=body-text>A continuation has the same notation as a state invariant, but is used in combined fragments and can stretch across more than one lifeline. </p>
<br><a href="http://www.sparxsystems.com/resources/uml2_tutorial/uml2_sequencediagram.html">http://www.sparxsystems.com/resources/uml2_tutorial/uml2_sequencediagram.html</a>
<img src ="http://www.cnitblog.com/houcy/aggbug/62563.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:06 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62563.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Use Case Diagram【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62562.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:02:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62562.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62562.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62562.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62562.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62562.html</trackback:ping><description><![CDATA[Use Case Model<br><span class=body-text>The use case model captures the requirements of a system. Use cases are a means of communicating with users and other stakeholders what the system is intended to do.</span>
<p class=body-text-bld>Actors<br><span class=body-text>A use case diagram shows the interaction between the system and entities external to the system. These external entities are referred to as actors. Actors represent roles which may include human users, external hardware or other systems. An actor is usually drawn as a named stick figure, or alternatively as a class rectangle with the &#171;actor&#187; keyword.</span> </p>
<table width="100%" border=0>
    <tbody>
        <tr>
            <td width="16%"><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc01.gif" width=87> </td>
            <td width="84%"><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc02.GIF" width=130> </td>
        </tr>
    </tbody>
</table>
<p class=body-text>Actors can generalize other actors as detailed in the following diagram: </p>
<p class=body-text><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc05.GIF" width=259> </p>
<p><span class=body-text-bld>Use Cases</span><br><span class=body-text>A use case is a single unit of meaningful work. It provides a high-level view of behavior observable to someone or something outside the system. The notation for a use case is an ellipse.</span> </p>
<p class=body-text><img height=120 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc10.GIF" width=145> </p>
<p class=body-text><br>The notation for using a use case is a connecting line with an optional arrowhead showing the direction of control. The following diagram indicates that the actor "Customer" uses the "Withdraw" use case. </p>
<p class=body-text><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc09.GIF" width=284> </p>
<p class=body-text>The uses connector can optionally have multiplicity values at each end, as in the following diagram, which shows a customer may only have one withdrawal session at a time, but a bank may have any number of customers making withdrawals concurrently. </p>
<p class=body-text><img height=140 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc07.GIF" width=416> </p>
<p class=body-text><span class=body-text-bld>Use Case Definition</span><br>A use case typically Includes: </p>
<ul class=body-text>
    <li>Name and description
    <li>Requirements
    <li>Constraints
    <li>Scenarios
    <li>Scenario diagrams
    <li>Additional information. </li>
</ul>
<p>&nbsp;</p>
<p><span class=body-text-bld>Name and Description</span><br><span class=body-text>A use case is normally named as a verb-phrase and given a brief informal textual description.</span> </p>
<p><span class=body-text-bld>Requirements</span><br><span class=body-text>The requirements define the formal functional requirements that a use case must supply to the end user. They correspond to the functional specifications found in structured methodologies. A requirement is a contract or promise that the use case will perform an action or provide some value to the system.</span> </p>
<p><span class=body-text-bld>Constraints</span><br><span class=body-text>A constraint is a condition or restriction that a use case operates under and includes pre-, post- and invariant conditions. A precondition specifies the conditions that need to be met before the use case can proceed. A post-condition is used to document the change in conditions that must be true after the execution of the use case. An invariant condition specifies the conditions that are true throughout the execution of the use case</span>. </p>
<p><span class=body-text-bld>Scenarios</span><br><span class=body-text>A Scenario is a formal description of the flow of events that occur during the execution of a use case instance. It defines the specific sequence of events between the system and the external actors. It is normally described in text and corresponds to the textual representation of the sequence diagram.</span> </p>
<p><span class=body-text-bld>Including Use Cases</span><br><span class=body-text>Use cases may contain the functionality of another use case as part of their normal processing. In general it is assumed that any included use case will be called every time the basic path is run. An example of this is to have the execution of the use case &lt;Card Identification&gt; to be run as part of a use case &lt;Withdraw&gt;.</span><br><img height=120 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc06.GIF" width=341> </p>
<p class=body-text>Use Cases may be included by one or more Use Case, helping to reduce the level of duplication of functionality by factoring out common behavior into Use Cases that are re-used many times. </p>
<p class=body-text><span class=body-text-bld>Extending Use Cases</span><br>One use case may be used to extend the behavior of another; this is typically used in exceptional circumstances. For example, if before modifying a particular type of customer order, a user must get approval from some higher authority, then the &lt;Get Approval&gt; use case may optionally extend the regular &lt;Modify Order&gt; use case. </p>
<p class=body-text><img height=120 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc03.GIF" width=321> </p>
<p class=body-text><span class=body-text-bld>Extension Points</span><br>The point at which an extending use case is added can be defined by means of an extension point. </p>
<p class=body-text><img height=222 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc04.GIF" width=380> </p>
<p class=body-text><span class=body-text-bld>System Boundary</span><br>It is usual to display use cases as being inside the system and actors as being outside the system.<br><br><img height=240 src="http://www.sparxsystems.com/images/screenshots/uml2_tutorial/uc08.GIF" width=325>&nbsp;<br><br><a href="http://www.sparxsystems.com/resources/uml2_tutorial/uml2_usecasediagram.html">http://www.sparxsystems.com/resources/uml2_tutorial/uml2_usecasediagram.html</a></p>
<img src ="http://www.cnitblog.com/houcy/aggbug/62562.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:02 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62562.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How do you use the UML? 【转】</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62561.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 03:01:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62561.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62561.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62561.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62561.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62561.html</trackback:ping><description><![CDATA[<p>The UML is typically used as a part of a software development process, with the support of a suitable CASE tool, to define the requirements, the interactions and the elements of the proposed software system. The exact nature of the process depends on the development methodology used. An example process might look something like the following: </p>
<p>1.&nbsp; Capture a Business Process Model. This will be used to define the high level business activities and processes that occur in an organization and to provide a foundation for the Use Case model. The Business Process Model will typically capture more than a software system will implement (ie. it includes manual and other processes).&nbsp; <br>2.&nbsp; Map a Use Case Model to the Business Process Model to define exactly what functionality you are intending to provide from the business user perspective. As each Use Case is added, create a traceable link from the appropriate business processes to the Use Case (ie. a realisation connection). This mapping clearly states what functionality the new system will provide to meet the business requirements outlined in the process model. It also ensures no Use Cases exist without a purpose.&nbsp; <br>3.&nbsp; Refine the Use Cases - include requirements, constraints, complexity rating, notes and scenarios. This information unambiguously describes what the Use Case does, how it is executed and the constraints on its execution. Make sure the Use Case still meets the business process requirements. Include the definition of system tests for each use case to define the aceptance criteria for each use case. Also include some user acceptance test scripts to define how the user will test this functionality and what the acceptance criteria are.&nbsp; <br>4.&nbsp; From the inputs and outputs of the Business Process Model and the details of the use cases, begin to construct a domain model (high level business objects), sequence diagrams, collaboration diagrams and user interface models. These describe the 'things' in the new system, the way those things interact and the interface a user will use to execute use case scenarios.&nbsp; <br>5.&nbsp; From the domain model, the user interface model and the scenario diagrams create the Class Model. This is a precise specification of the objects in the system, their data or attributes and their behaviour or operations. Domain objects may be abstracted into class hierarchies using inheritance. Scenario diagram messages will typically map to class operations. If an existing framework or design pattern is to be used, it may be possible to import existing model elements for use in the new system. For each class define unit tests and integration tests to thoroughly test i) that the class functions as specified internally and that ii) the class interacts with other related classes and components as expected.&nbsp; <br>6.&nbsp; As the Class Model develops it may be broken into discrete packages and components. A component represents a deployable chunk of software that collects the behaviour and data of one or more classes and exposes a strict interface to other consumers of its services. So from the Class Model a Component Model is built to define the logical packaging of classes. For each component define integration tests to confirm that the component's interface meets the specifcation given it in relation to other software elements.&nbsp; <br>7.&nbsp; Concurrent with the work you have already done, additional requirements should have been captured and documented. For example - Non Functional requirements, Performance requirements, Security requirements, responsibilities, release plans &amp; etc. Collect these within the model and keep up to date as the model matures.&nbsp; <br>8.&nbsp; The Deployment model defines the physical architecture of the system. This work can be begun early to capture the physical deployment characteristics - what hardware, operating systems, network capabilities, interfaces and support software will make up the new system, where it will be deployed and what parameters apply to disaster recovery, reliability, back-ups and support. As the model develops the physical architecture will be updated to reflect the actual system being proposed.&nbsp; <br>9.&nbsp; Build the system: Take discrete pieces of the model and assign to one or more developers. In a Use Case driven build this will mean assigning a Use Case to the development team, having them build the screens, business objects, database tables, and related components necessary to execute that Use Case. As each Use Case is built it should be accompanied by completed unit, integration and system tests. A Component driven build may see discrete software components assigned to development teams for construction.&nbsp; <br>10.&nbsp; Track defects that emerge in the testing phases against the related model elements - eg. System test defects against Use Cases, Unit Test defects against classes &amp; etc. Track any changes against the related model elements to manage 'scope creep'.&nbsp; <br>11.&nbsp; Update and refine the model as work proceeds - always assessing the impact of changes and model refinements on later work. Use an iterative approach to work through the design in discrete chunks, always assessing the current build, the forward requirements and any discoveries that come to light during development.&nbsp; <br>12.&nbsp; Deliver the complete and tested software into a test then production environment. If a phased delivery is being undertaken, then this migration of built sofware from test to production may occur several times over the life of the project.&nbsp; </p>
<p>Note that the above process is necessarily brief in description, leaves much unsaid and may not be how you work or follow the process you have adopted. It is given as an example of how the UML may be used to support a software development project. <br><br><br><a href="http://www.sparxsystems.com/resources/tutorial/uml_tutorial2.html">http://www.sparxsystems.com/resources/tutorial/uml_tutorial2.html</a></p>
<img src ="http://www.cnitblog.com/houcy/aggbug/62561.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 11:01 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62561.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The Business Process Model [转]</title><link>http://www.cnitblog.com/houcy/archive/2009/11/13/62560.html</link><dc:creator>挑灯看剑</dc:creator><author>挑灯看剑</author><pubDate>Fri, 13 Nov 2009 02:58:00 GMT</pubDate><guid>http://www.cnitblog.com/houcy/archive/2009/11/13/62560.html</guid><wfw:comment>http://www.cnitblog.com/houcy/comments/62560.html</wfw:comment><comments>http://www.cnitblog.com/houcy/archive/2009/11/13/62560.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/houcy/comments/commentRss/62560.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/houcy/services/trackbacks/62560.html</trackback:ping><description><![CDATA[<h3>Introduction</h3>
<p>Traditionally, the UML has been associated more with software engineering and systems design than with analysis and modeling of business processes. However, standard UML 2.x provides a rich set of behavioral models which are very useful in modeling the processes, activities, people and information critical to every business. </p>
<p>Beyond the standard UML notation, two well respected and proven UML &#8220;extensions&#8221; exist which further enhance the capturing of business process and related constructs. The first is Business Process Modeling Notation (BPMN), which has gained enormous popularity and is rapidly becoming a new standard for modeling and designing business processes. The second is the Ericsson-Penker profile which has less popularity, but still provides a unique and powerful means of visualizing and communicating business processes and the necessary flow of information within an organization. </p>
<p>This paper provides a very high-level introduction to both of these &#8220;extensions&#8221;, showing how they can be used in Enterprise Architect and some of the common modeling constructs they use. </p>
<p>&nbsp; </p>
<h3>Business Process Modeling Notation (BPMN)</h3>
<p>BPMN defines a Business Process Diagram (BPD), which is based on a flowcharting technique tailored for creating graphical models of business process operations. It is a notation that is readily understandable by all business users, from the business analysts that create the initial drafts of the processes, to the technical developers responsible for implementing the technology that will perform those processes, and finally, to the business people who will manage and monitor those processes. </p>
<p>A BPMN model consists of simple diagrams with a small set of graphical elements. </p>
<h5><em>Flow Elements</em></h5>
<ol>
    <li>Activities. An activity is work that is performed within a business process and is represented by a rounded rectangle.
    <li>Events. An event is something that happens during the course of a business process which affects the sequence or timing of activities of a process. Events are represented as small circles with different boundaries to distinguish start events (thin black line), intermediate events (double line) and end events (thick black line). Events can show icons within their shape to identify the trigger or result of the event.
    <li>Gateways. Gateways are used to control how sequence flows converge and diverge within a process. Gateways can represent decisions, where one or more paths are disallowed, or they can represent concurrent forks. </li>
</ol>
<ol>
    <li>Sequence flows. A sequence flow is used to show the order in which activities are performed within a process. A sequence flow is represented by a line with a solid arrowhead.
    <li>Message flows. A message flow is used to show the flow of messages between two entities, where pools are used to represent entities. A message flow is represented by a dashed line with a light-colored circle at the source and arrowhead at the target.
    <li>Associations. An association is used to associate information and artifacts with flow objects. An association is represented by a dashed line which may or may not have a line arrowhead at the target end if there is a reason to show directionality. </li>
</ol>
<h5><em>Swimlanes (Partitions)</em></h5>
<ol>
    <li>Pools. A pool represents a participant in a process, where a participant may be a business entity or role. It is represented as a partition of the process.
    <li>Lanes. A lane is a sub-division of a pool and is used to organize and categorize activities within the pool. </li>
</ol>
<h5><em>Artifacts</em></h5>
<ol>
    <li>Data objects. A data object does not have a direct affect on a process but does provide information relevant to the process. It is represented as a rectangle with the top corner folded over.
    <li>Groups. A group is an informal means for grouping elements of a process. It is represented as a rectangle with a dashed line border.
    <li>Annotations. An annotation is a mechanism for the BPMN modeler to provide additional information to the audience of a BPMN diagram. It is represented by an open rectangle containing the annotation text. </li>
</ol>
<h5><em>BPMN Examples</em></h5>
<blockquote>
<p><strong>Example 1:</strong> </p>
</blockquote>
<p><img height=268 alt="Example 1" src="http://www.sparxsystems.com/images/screenshots/BPMNExample1.png" width=689> </p>
<p>The above diagram illustrates a number of key features of BPMN, specifically the ability to create hierarchical decomposition of processes into smaller tasks, the ability to represent looping constructs and the ability to have external events interrupt the normal process flow. </p>
<p>"Upstream Activities" and "Downstream Activities" are link-triggered intermediate events; in other words, off-page connectors. </p>
<p>"Repeat for Each Supplier" is a looping activity, which repeats its three contained activities either once for each supplier or until a time limit is exceeded. The intermediate event mounted on the lower edge of the activity is a time-triggered event. </p>
<blockquote>
<p><strong>Example 2:</strong> </p>
</blockquote>
<p><img height=199 alt="Example 2" src="http://www.sparxsystems.com/images/screenshots/BPMNExample2.png" width=590> </p>
<p>The above diagram shows a process being initiated by an event - in this case a message-triggered start event which notifies the process that the working group is active. The diagram also shows a loop being controlled by a timer event, and it shows a decision gateway (in this case, an XOR decision gateway) controlling when the loop is terminated. </p>
<blockquote>
<p><strong>Example 3:</strong> </p>
</blockquote>
<p><img height=336 alt="Example 3" src="http://www.sparxsystems.com/images/screenshots/BPMNExample3.png" width=390> </p>
<p>This diagram illustrates the use of pools to show interacting processes and the way that messages are passed between pools using message flow connectors. </p>
<p>&nbsp; </p>
<h3>Eriksson-Penker Business Modeling Profile</h3>
<p>This section provides an introduction to the terminology and icons used in the Business Process Model, and gives a quick introduction to some Unified Modeling Language (UML) concepts and how they are applied in Enterprise Architect's Business Process Model. </p>
<p>A business process: </p>
<ol>
    <li>Has a Goal
    <li>Has specific inputs
    <li>Has specific outputs
    <li>Uses resources
    <li>Has a number of activities that are performed in some order
    <li>May affect more than one organizational unit. Horizontal organizational impact
    <li>Creates value of some kind for the customer. The customer may be internal or external. </li>
</ol>
<p><img height=263 alt="Eriksson-Penker Business Modeling Profile" src="http://www.sparxsystems.com/images/screenshots/BusinessProcessModel.png" width=641> </p>
<h5><em>Process Models</em></h5>
<p>A business process is a collection of activities designed to produce a specific output for a particular customer or market. It implies a strong emphasis on how the work is done within an organization, in contrast to a product's focus on what a process is. Thus a specific ordering of work activities across time and place, with a beginning, an end, and clearly defined inputs and outputs: a structure for action. </p>
<p>Supply link from object <em>Information</em>. A supply link indicates that the information or object linked to the process is not used up in the processing phase. For example, order templates may be used over and over to provide new orders of a certain style &#8211; the templates are not altered or exhausted as part of this activity. </p>
<ul>
    <li>Supply link from object <em>Resource</em>. An input link indicates that the attached object or resource is consumed in the processing procedure. As an example, as customer orders are processed they are completed and signed off, and typically are used only once per unique resource (order).
    <li>Goal link to object <em>Goal</em>. A goal link indicates the attached object to the business process describes the goal of the process. A goal is the business justification for performing the activity.
    <li>Object flow link to object <em>Output</em>
    <li>Object flow link from event <em>Event</em>. An object flow link indicates some object is passed into a business process. It captures the passing of control to another entity or process, with the implied passing of state or information from activity to activity. </li>
</ul>
<h5>&nbsp;</h5>
<h5><em>Goal</em></h5>
<p>A business process has some well defined goal. This is the reason the organization does this work, and should be defined in terms of the benefits this process has for the organization as a whole and in satisfying the business needs. </p>
<p>Goals link to Processes. A Goal link indicates the attached object to the business process describes the goal of the process. A goal is the business justification for performing the activity. </p>
<h5><em>Information</em></h5>
<p>Business processes use information to tailor or complete their activities. Information, unlike resources, is not consumed in the process &#8211; rather it is used as part of the transformation process. Information may come from external sources, from customers, from internal organizational units and may even be the product of other processes. </p>
<p>Information items link to Business Processes. A Supply link indicates that the information or object linked to the process is not used up in the processing phase. For example, order templates may be used over and over to provide new orders of a certain style &#8211; the templates are not altered or exhausted as part of this activity. </p>
<h5><em>Output</em></h5>
<p>A business process will typically produce one or more outputs of value to the business, either for internal use of to satisfy external requirements. An output may be a physical object (such as a report or invoice), a transformation of raw resources into a new arrangement (a daily schedule or roster) or an overall business result such as completing a customer order. </p>
<p>An output of one business process may feed into another process, either as a requested item or a trigger to initiate new activities. </p>
<h5><em>Resource</em></h5>
<p>A resource is an input to a business process, and, unlike information, is typically consumed during the processing. For example, as each daily train service is run and actuals recorded, the service resource is 'used up' as far as the process of recording actual train times is concerned. </p>
<p>Resources link to Business Processes. An Input link indicates that the attached object or resource is consumed in the processing procedure. As an example, as customer orders are processed they are completed and signed off, and typically are used only once per unique resource (order). </p>
<br>原文出处：<br><a href="http://www.sparxsystems.com/business_process_model.html">http://www.sparxsystems.com/business_process_model.html</a>
<img src ="http://www.cnitblog.com/houcy/aggbug/62560.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/houcy/" target="_blank">挑灯看剑</a> 2009-11-13 10:58 <a href="http://www.cnitblog.com/houcy/archive/2009/11/13/62560.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>