1. 程式人生 > >UML基本架構建模--類的術語和概念

UML基本架構建模--類的術語和概念

Terms and Concepts

術語和概念

A classis a description of a set of objects that share the same attributes, operations, relationships, and semantics. Graphically, a class is rendered as a rectangle.

一個類描述一組物件,這組物件共享相同的屬性,操作,關係和語義.圖形上,一個類被表達為一個矩形.

Names

名稱

Every class must have a name that distinguishes it from other classes. A

name is a textual string. That name alone is known as a simple name; aqualifiednameis the class name prefixed by the name of the package in which that class lives. A class may be drawn showing only its name, as Figure 4-2 shows.

每個類必須有一個名稱以區別於其它的燈.一個名稱是一個文字字串.這個名稱被稱為一個簡單的名稱;一個合格的名稱是帶有這個名稱所在包的字首的名稱.一個類可能只畫出它的名稱,就像圖4-2顯示的.

Note:A class name may be text consisting of any number of letters, numbers, and certain punctuation marks (except for marks such as the double colon, which is used to separate a class name and the name of its enclosing package) and may continue over several lines. In practice, class names are short nouns or noun phrases drawn from the vocabulary of the system you are modeling. Typically, you capitalize the first letter of every word in a class name, as in

Customer orTemperatureSentor.

備註:一個類名可以是由任意個字母,數字和某些標點符號組成(除了雙冒號,它通常用來分隔類名和封裝此類名的包)的文字,類名也可能超過多行.在實際中,類名通常來自你正在建模的系統的詞彙表中的短名詞或名詞短語.通常類名的每個單詞的首字母需大寫,如CustomerTemperatureSentor

Attributes

屬性

Anattribute is a named property of a class that describes a range of values that instances of the property may hold. A class may have any number of attributes or no attributes at all. An attribute represents some property of the thing you are modeling that is shared by all objects of that class. For example, every wall has a height, width, and thickness; you might model your customers in such a way that each has a name, address, phone number, and date of birth. An attribute is therefore an abstraction of the kind of data or state an object of the class might encompass. At a given moment, an object of a class will have specific values for every one of its classs attributes. Graphically, attributes are listed in a compartment just below the class name. Attributes may be drawn showing only their name, as shown in Figure 4-3.

一個屬性確定一個類的特性,用來描述特性例項值的範圍.一個類可能有多個屬性也可能根本沒有屬性.一個屬性表示的是你正在構建的類的所有物件共享的那些特性.例如,每面牆有高度,寬度和厚度;你也許在以這樣一種方式構建你的客戶模型:每個客戶有一個名字,地址,電話號碼和出生日期.一個屬性是資料型別的抽象或是這個類的物件所包含的狀態.在給定的時刻,一個類的一個物件將為它的每一個類屬性設定特定的值.圖形表現上,屬性被列在類名稱下的分隔欄內.屬性可以只顯示它們的名稱,如圖4-3顯示的那樣.

Note:An attribute name may be text, just like a class name. In practice, an attribute name is a short noun or noun phrase that represents some property of its enclosing class. Typically, you capitalize the first letter of every word in an attributes name except the first letter, as inname orloadBearing.

備註:一個屬性的名稱就象類名一樣可以是文字.在實際中,一個屬性的名稱是短名詞或名詞短語,代表封裝它的類的一些性質.通常屬性名稱除了第一個單詞外的其它單詞的首字母需大寫,如nameloadBearing

You can further specify an attribute by stating its class and possibly a default initial value, as shown Figure 4-4.

你可以通過類的狀態和預設初始值來進一步說明屬性,就如圖4-4顯示的.

Operations

操作

Anoperationis the implementation of a service that can be requested from any object of the class to affect behavior. In other words, an operation is an abstraction of something you can do to an object that is shared by all objects of that class. A class may have any number of operations or no operations at all. For example, in a windowing library such as the one found in Javasawt package, all objects of the classRectangle can be moved, resized, or queried for their properties. Often (but not always), invoking an operation on an object changes the objects data or state. Graphically, operations are listed in a compartment just below the class attributes. Operations may be drawn showing only their names, as in Figure 4-5.

一個操作是一種服務,可以實現來自這個類的任何物件請求,以影響其行為.另一方面,一個操作是你對一個物件的動作被該類的所有物件所共享的抽象行為.一個類可以擁有任何數量的操作,也可以根本沒有操作.舉個例子,在視窗庫中,如在Java AWT包中找到的,類Rectangle的所有物件都可以被移動,可調整大小,或者查詢它們的屬性.通常(但不總是)在一個物件上呼叫一個操作改變這個物件的資料或是狀態.圖形表示上,操作被列在類屬性下的分隔欄內.操作可以只顯示它們的名稱,如圖4-5顯示的.

Note:An operation name may be text, just like a class name. In practice, An operation name is a short verb or verb phrase that represents some behavior of its enclosing class. Typically, you capitalize the first letter of every word in an operation name except the first letter, as inmove orisEmpty.

備註:一個操作的名稱就象類名一樣可以是文字.在實際中,一個操作的名稱是簡單動詞或動詞短語,代表封裝它的類的一些行為.通常操作名稱除了第一個單詞外的其它單詞的首字母需大寫,如moveisEmpty

You can specify an operation by stating its signature, which includes the name, type, and default value of all parameters and (in the case of functions) a return type, as shown in Figure 4-6.

你可以通過描述它標籤說明一個操作,標籤包括名稱,型別,所有引數的預設值和(在函式的情況下)返回型別,象圖4-6顯示的.