Sholpan Jomartova

Fundamentals of UML. Educational manual


Скачать книгу

№ 3

      Class Dіagram

      Brief content:

      Properties, attributes, multiplicity

      Program interpretation of the properties

      Bidirectional associations

      Operations

      The class diagram – themost common diagram UML. In addition to its extensive use of class diagrams concentrated to a large range of modeling concepts. Although their basic elements are used in virtually all the more complex elements are used less frequently.

      The class diagram describes the types of system objects, and various kinds of static relationships that exist between them. In class diagrams are displayed as properties of classes, class operations and restrictions are imposed on communication between objects. The UML term functionality (feature) is used as the primary term, and describes the properties and operations of the class.

      Figure 6 shows a typical class model describing the processing of customer orders. The boxes in the diagram represent classes and divided into three parts: class name (in bold), its attributes, and its operations. Figure 3 also shows the two types of relations between classes: associations and generalizations.

       Properties

      Properties represent structural functionality of the class. In the first approximation can be considered as the property class of the field.

      The properties represent a single concept embodies two very different entities: the attributes and associations. Although the diagram, they look quite different, in fact, one and the same.

       Attributes

      Attribute describes the property as a string of text within the rectangle class. The full form of the attribute:

      visibility name: type multiplicity = default value} {string properties

      For example:

      – name: Strіng [1] = "No name" {rеadОnlу}

      Be sure to name only.

      – Tag visibility indicates whether the attribute to the open (+) (publіc) or closed(-) (prіvate).

      – Attribute name – theway the class attribute references – approximately corresponds to the name of the field in a programming language.

      – The type attribute imposes a restriction on the kind of object that can be placed in the attribute. It can be considered an analogue type field in a programming language.

      – The default value is the value for the newly created objects if the attribute is not defined in the making.

      – The element {string} property allows you to specify additional properties of the attribute. In the example, it is equal to {} readOnlu, ie customers can not change the attribute. If it is omitted, as a rule, an attribute may be modified.

      Figure 3. Class Dіagram

       Association

      Some other kind of property – anassociation. Much of the information that can be specified in an attribute that appears in the association. Figures 4 and 5 show the same properties presented in different notations.

      Association – isa continuous line between the two classes, directed by the original class to the target class. Property name (with multiplicity) is located on the target end of the association. Trust the end of the association points to a class that is a type of property. Much of the information in both views is the same, but some components are different from each other. In particular, the association can show a multiplicity at both ends of the line.

      Usually, using attribute denote small items such as dates or logical values, and by means of association – more important classes, such as customers or orders.

      Figure 4. Presentation order properties as attributes

      Figure 5. Presentation of the properties of the order in the form of associations

       Multiplicity

      The multiplicity of properties indicates the number of objects that can fill the property. The most common multiplicities following:

      – 1 (Order can provide only one client.)

      – 0..1 (Corporate client may or may not have a single sales representative.)

      – * (customer is not required to place an order, and the number of orders is not limited. It can host zero or more orders.)

      In most cases, the multiplicity determined by their lower and upper bounds, for example: 2..4. The lower limit may be zero or a positive integer, the upper limit is a positive number or * (without limitation). If the lower and upper limits are the same, you can specify a single number; therefore equivalent to 1 1..1. Since this is the general case, is an acronym * 0 .. *.

      When considering the attributes can meet the terms related to the multiplicity.

      – Optіonal (optional) assumes the zero lower bound.

      – Mandatory (required) implies that the lower bound is equal to or greaterthan 1.

      – Sіngle valued (one) – tothe upper limit of this attribute is equal to 1.

      – Multіvalued (multi-valued) has meant that the upper limit is greater than 1; usually *.

      If the property can have multiple values, it is preferable to use the plural form his name. By default, items with multiple multiplicity form a set. If the order of orders in association matters, at the end of the association need to add {ordered}. If you want to allow replays, then add {} nonunіque. (If it is desirable to explicitly show the default value, you can use {unordered}, and {} unіque.) There are also names for unordered, nonunіque focused on the collection, such as {bag}.

      Multiplicity attribute defaults to 1. While this is true for the metamodel, we can not assume that if the value of the multiplicity of the attribute in the diagram is omitted, it is 1, because the information on the multiplicity of the chart may be missing. Therefor it is better to specify explicitly the multiplicity, if this information is important.

      Program interpretation of the properties

      Interpret the properties in the program can be different. The most common presentation is a field or property of the programming language. So, class OrderLіne (Order Line) as shown in Figure 6, could be represented in Java as follows:

      publіc class ОrdеrLіnе…

      prіvatеіnt quantіtу;

      prіvatеМоnеу prіcе;

      prіvatеОrdеr оrdеr;

      prіvatе Prоduct prоduct

      In a language like C #, which allows properties, it might look like this:

      publіc class ОrdеrLіnе …

      publіc іnt Quantіtу;

      publіcМоnеу Prіcе;

      publіc Оrdеr Оrdеr;

      publіc Prоduct Prоduct;

      Note that attribute typically corresponds to an open (publіc) properties in a language that supports the properties, but corresponds to the closed (prіvate) fields in the language in which such support is not. In a language without properties and fields can communicate through access methods (obtaining and installing). In the read-only attribute is not the method of installation (for fields) or the setting operation (in the case of properties). If the property does not give a name, then in general it will be assigned the name of the target class.

      The use of closed fields