SAD Chapter 6: Behavioral Modeling –UML ObjectInteraction
Interaction Diagrams 互動(dòng)圖(交互圖)
?An Interaction diagram shows step-by-step, one of theflows through a use case: what objects are needed for the flow, what messagesthe objects send to each other, what actor initiates the flow, and what orderthe messages are sent.
一個(gè)互動(dòng)圖(交互圖)一步步顯示了一個(gè)用例中的流程之一:該流程需要哪些對(duì)象,這些對(duì)象彼此之間發(fā)送哪些消息,哪個(gè)參與者發(fā)起該流程以及消息的發(fā)送順序。
?Sequence diagrams can show a focus of control;Communication diagrams can show a data flow.
循序圖(時(shí)序圖)可以顯示執(zhí)行事件;通訊圖可以顯示數(shù)據(jù)流。
?While the flow of events focuses on what the systemneeds to do, Sequence and Communication diagrams help to define how the systemwill do it.
事件流著重于系統(tǒng)需要做什么,而循序圖(時(shí)序圖)和通訊圖則有助于定義系統(tǒng)的工作方式。
?The steps involved in creating a Sequenceor Communication diagram are:
創(chuàng)建循序圖(序列圖)或通訊圖的步驟包括:
? Find the objects.?? 找到對(duì)象
? Find the actor.????? 找到參與者
Add messages to the diagram. 向圖中添加消息
Categories of Objects 對(duì)象(物件)的種類
?Entity objects?These are objects that hold information. They may eventually map to some of the tables and fields in the database.
實(shí)體對(duì)象(物件):保存信息的對(duì)象。它們最終可能會(huì)映射到數(shù)據(jù)庫(kù)中的某些表和字段。
?Boundary objects?These are objects that lie on the boundary between the system and the outside world. In other words, these are the forms and windows of the application and theinterfaces to other applications.
邊界對(duì)象(物件):這些對(duì)象位于系統(tǒng)和外界之間的邊界上。換句話說(shuō),這些是應(yīng)用程序的形式和窗口以及與其他應(yīng)用程序的接口。
?Control objects?These are optional objects that control the flow through the use case. They don't carry out any business functionality in and of themselves.
控制對(duì)象(物件):這些是可選對(duì)象(物件),用于控制通過(guò)用例的流程。他們本身并不執(zhí)行任何業(yè)務(wù)功能。
Sequence Diagrams 循序圖(時(shí)序圖)
?Sequence diagramsare Interaction diagrams that are ordered by time; we read thediagram from the top to the bottom. 循序圖(時(shí)序圖)是按時(shí)間排序的交互圖;我們從上至下閱讀該圖。
?Each object has alifeline, drawn as avertical dashed line below the object. Each message represents one object making a function call of another.
每個(gè)對(duì)象(物件)都有一條生命線,在對(duì)象下方以垂直虛線繪制。每個(gè)消息代表一個(gè)對(duì)象(物件),該對(duì)象(物件)對(duì)另一個(gè)對(duì)象(物件)進(jìn)行函數(shù)調(diào)用。
Communication Diagrams 通訊圖
?While Sequence diagrams are ordered by time,Communication diagrams focus more on the relationships between the objects. 雖然時(shí)序圖按時(shí)間排序,但通訊圖更多地關(guān)注對(duì)象之間的關(guān)系。
?On a Sequence or Communication diagram,each object may be mapped to a class.
在循序圖(時(shí)序圖)或通訊圖上,每個(gè)對(duì)象(物件)都可以映射到一個(gè)類。
Setting Object Persistence 設(shè)置對(duì)象(物件)持久性
?PersistentApersistent object is one that will be saved to a database or to some other formof persistent storage.??? 持久?????? 持久對(duì)象是指被保存到數(shù)據(jù)庫(kù)或某種其他形式的持久存儲(chǔ)中的對(duì)象。
?StaticAstatic object is one that stays in memory until the program is terminated.
靜態(tài)???? 靜態(tài)對(duì)象是在程序終止之前一直保留在內(nèi)存中的對(duì)象。
?TransientAtransient object is one that stays in memory only for a short time.
瞬態(tài)???? 瞬態(tài)對(duì)象是僅在內(nèi)存中保留很短時(shí)間的對(duì)象。
Mapping a Message to an Operation???? 將消息映射到方法
?Before you generate code, each message on yourSequence and Communication diagrams should be mapped to an operation of aclass.
生成代碼之前,應(yīng)將序循序圖(時(shí)序圖)與 通訊圖上的每個(gè)消息映射到一個(gè)類的方法。
Simple?? 簡(jiǎn)單
?This is the default value for messages. This option specifies that the message runs in a single thread of control.? 這是消息的默認(rèn)值。 此選項(xiàng)指定消息在單個(gè)控制線程中運(yùn)行。
Synchronous??????? 同步
?Use this option when the client sends themessage and waits until the supplier has acted upon the message.
當(dāng)客戶端發(fā)送消息并等待供應(yīng)商(supplier)對(duì)消息采取行動(dòng)之前,請(qǐng)使用此選項(xiàng)。
Balking
?With this option, the client sends the message to thesupplier. If the supplier is not immediately ready to accept the message, the client abandons the message.
使用此選項(xiàng),客戶端將消息發(fā)送給供應(yīng)商。 如果供應(yīng)商尚未立即準(zhǔn)備好接受該消息,則客戶端將放棄該消息。
Timeout 超時(shí)
?Using this option, the client sends the message to thesupplier and waits a specified amount of time. If the supplier isn't ready to receive the message in that time, the client abandons the message.
客戶端使用此選項(xiàng)將消息發(fā)送給供應(yīng)商,并等待指定的時(shí)間。 如果供應(yīng)商當(dāng)時(shí)還沒(méi)有準(zhǔn)備好接收消息,則客戶端放棄該消息。
Asynchronous 異步
?With this option, the client sends the message to the supplier. The client then continues processing, without waiting to see if the message was received or not.
使用此選項(xiàng),客戶端將消息發(fā)送給供應(yīng)商。 然后,客戶端繼續(xù)處理,而無(wú)需等待查看是否已收到消息。
Procedure Call???? 程序調(diào)用
?With this option, the client sends the message to the supplier. The client then must wait until the entire nested sequence of messages is processed before continuing.
使用此選項(xiàng),客戶端將消息發(fā)送給供應(yīng)商。 然后,客戶端必須等待,直到處理完整個(gè)嵌套的消息序列為止,然后才能繼續(xù)。
Return?? 返回
?This option indicates the return from a procedure call.?????? 此選項(xiàng)指示從過(guò)程調(diào)用返回。
Setting Message Frequency???? 設(shè)置消息頻率
?Message frequency lets you mark a message to be sent at regular intervals.
消息頻率使您可以標(biāo)記要定期發(fā)送的消息。
For example, you have a message that should run once every 30 seconds. You can set that message to be periodic.???????? 例如,您有一條消息,應(yīng)該每30秒運(yùn)行一次。您可以將該消息設(shè)置為定時(shí)的。
End of a Lifeline?? 生命線的結(jié)束
?The destruction marker is used to indicate the end of a lifeline. It appears as an "X" on the lifeline itself, and thelifeline will not extend beyond it.
毀滅標(biāo)記用于指示生命線的結(jié)束。 它在生命線本身上顯示為“ X”,并且生命線不會(huì)超出其范圍。
Working with Scripts? 使用腳本
?Scripts are usually used to add a comment to a message and are only used on Sequence diagrams.
腳本通常用于在消息中添加注釋,并且僅用于循序圖(時(shí)序圖)。
?They are usually placed on the left sideof the diagram, opposite the message they refer to.
它們通常放置在圖的左側(cè),與它們所引用的消息相反。
Working with Classes
?There are several types of classes including regularclasses, parameterized classes, instantiated classes, class utilities, and soon.?? 有幾種類型的類,包括常規(guī)類,參數(shù)化類,實(shí)例化類,類實(shí)用程序等。
Class Stereotypes
?A stereotype is a mechanism you can use to categorize your classes.
構(gòu)造型是一種可用于對(duì)類進(jìn)行分類的機(jī)制。
?Stereotypes also help in the code-generation process.????? Stereotypes也有助于代碼生成過(guò)程
Analysis Stereotypes
?There are three primary class stereotypes in UML that are used for analysis: boundary, entity, and control.
UML中有三種主要的類構(gòu)造型用于分析:邊界,實(shí)體和控制。
Boundary Classes?????? 邊界類
Boundary classes are those classes that lieon the boundary between your system and the rest of the world. These wouldinclude all of your forms, reports, interfaces to hardware such as printers orscanners, and interfaces to other systems.
邊界類位于系統(tǒng)與世界其他地方之間邊界上的類。 其中包括所有表單,報(bào)告,與打印機(jī)或掃描儀之類的硬件的接口以及與其他系統(tǒng)的接口。
?At a minimum, there must be one boundary class for every actor–use case interaction. The boundary class is what allows the actor to interact with the system. Two actors might both use the same boundary class to communicate with the system.?
對(duì)于每個(gè)參與者-用例交互,至少必須有一個(gè)邊界類。 邊界類是允許參與者與系統(tǒng)進(jìn)行交互的類。 兩個(gè)參與者可能都使用相同的邊界類與系統(tǒng)進(jìn)行通信。
Entity Classes?????? 實(shí)體類
?Entity classes hold information that you may save to persistent storage.
實(shí)體類保存您可以保存到持久性存儲(chǔ)中的信息。
?Each attribute in an entity class may become a field in the database.
實(shí)體類中的每個(gè)屬性都可以成為數(shù)據(jù)庫(kù)中的一個(gè)字段。
Control Classes??? 控制類
?Control classes are optional, but if a control class is used, there is typically one control class per use case.
控件類是可選的,但是如果使用控件類,則每個(gè)用例通常只有一個(gè)控件類。
?The control class doesn't carry out any functionality itself, and other classes don't send many messages to it. Instead, it sends out a lot of messages.
控件類本身不執(zhí)行任何功能,其他類也不向其發(fā)送太多消息。 相反,它發(fā)出很多消息。
?They execute alternative flows and know what to do in case of an error. For this reason, control classes are sometimes called manager classes.????
他們執(zhí)行替代流程并知道發(fā)生錯(cuò)誤時(shí)的處理方法。 因此,控制類有時(shí)稱為管理器類。
Class Types?? 類的種類
?In design, we want to categorize our classes using the terminology of the particular programming language we are going to use.????? 在設(shè)計(jì)中,我們希望使用將要使用的特定編程語(yǔ)言的術(shù)語(yǔ)對(duì)類進(jìn)行分類。
?Rose supports a number of different stereotypes for its different language options.
對(duì)于不同的語(yǔ)言選項(xiàng),Rose支持許多不同的構(gòu)造型。
Parameterized Class?? 參數(shù)化類別
?A parameterized class, the first of the special typesof classes we'll discuss, is a class that is used to create a family of otherclasses.??? 參數(shù)化類(我們將討論的特殊類型的第一種)是用于創(chuàng)建其他類族的類。
?The arguments for the class are displayed in the dashed-line box.
類的參數(shù)顯示在虛線框中。
Instantiated Class?????? 實(shí)例化類
?An instantiated class is a parameterized class that has actual values for the arguments. UML notation for an instantiated class is a class with the argument name enclosed in angle brackets (< >):
實(shí)例化的類是參數(shù)化的類,具有參數(shù)的實(shí)際值。 實(shí)例化類的UML表示法是一個(gè)類,其參數(shù)名稱包含在尖括號(hào)(<>)中:
Class Utility
?A class utility is a collection of operations. that are used throughout the system but don't fit well into any particular class. These functions can be gathered together and encapsulated into a class utility for use by the other classes in the system.
類實(shí)用程序是方法的集合。 在整個(gè)系統(tǒng)中使用,但不適用于任何特定類。 這些功能可以收集在一起并封裝到一個(gè)類實(shí)用程序中,以供系統(tǒng)中的其他類使用。
?A class utility will appear as a shadowed class on the diagram with this symbol:
類實(shí)用程序?qū)⒃趫D中帶有以下符號(hào)的陰影類中顯示:
Parameterized Class Utility????? 參數(shù)化類實(shí)用程序
?A parameterized class utility is a parameterized class that contains a set of operations. It is the template that is used to create class utilities. It appears on a Class diagram with the following symbol:
參數(shù)化類實(shí)用程序是包含一組操作的參數(shù)化類。 它是用于創(chuàng)建類實(shí)用程序的模板。 它顯示在類圖上,帶有以下符號(hào):
Instantiated Class Utility?? 實(shí)例化的類實(shí)用程序
?An instantiated class utility is a parameterized class utility that has values set for the parameters. It appears on a Class diagram as follows:??????
實(shí)例化的類實(shí)用程序是已為參數(shù)設(shè)置值的參數(shù)化類實(shí)用程序。 它在類圖上顯示如下:
Web Modeling Stereotypes
?Using this feature, you can more thoroughly describethe structure of your web applications, labeling which classes in the modelcorrespond to client pages, server pages, applets, session objects, or otherweb constructs.
使用此功能,您可以更徹底地描述Web應(yīng)用程序的結(jié)構(gòu),標(biāo)記模型中的哪些類對(duì)應(yīng)于客戶端頁(yè)面,服務(wù)器頁(yè)面,Applet,會(huì)話對(duì)象或其他Web構(gòu)造。
Setting Class Visibility 設(shè)置類的可見(jiàn)性
?The Visibility option determines whether or not aclass can be seen outside of its package. There are three visibility optionsfor a class:
可見(jiàn)性選項(xiàng)確定是否可以在包的外部看到類。 一個(gè)類有三個(gè)可見(jiàn)性選項(xiàng):
?PublicSuggeststhat the class can be seen by all of the other classes in the system.
Public? 建議類可以被系統(tǒng)中的所有其他類看到。
?Protected or PrivateSuggeststhat the class can be seen in nested classes, friends, or within the sameclass.?
Protected or Private?? 建議在類中可以在嵌套類,friends中或同一類中看到類。
?Package or ImplementationSuggests that the class can be seen only by other classes in the same package.? Package或Implementation???? 建議該類只能由同一包中的其他類看到。
access violation?? 訪問(wèn)沖突
?An access violation occurs in one of two situations:??? 在以下兩種情況之一中發(fā)生訪問(wèn)沖突
? §When there is a relationship between twoclasses in different packages, but there is no dependency relationship betweenthe packages themselves
當(dāng)不同包中的兩個(gè)類之間存在關(guān)系時(shí),但包本身之間沒(méi)有依賴關(guān)系
? §When there is a relationship between classes in different packages, and the supplier class has implementation visibility??????????? 當(dāng)不同包中的類之間存在關(guān)系并且供應(yīng)商類具有實(shí)現(xiàn)可見(jiàn)性時(shí)
Setting Class Multiplicity? 設(shè)置類多重性
?The Multiplicity field gives you a place to set the number of instances that you expect to have of a class.
“多樣性”字段為您提供了一個(gè)位置,用于設(shè)置您希望一個(gè)類擁有的實(shí)例數(shù)。