Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
1-30_Teoria.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
2.59 Mб
Скачать

7. Attributes and operations on class diagram: definitions,

The attribute notation describes a property as a line of text within the class box itself. The full form of an attribute is:

visibility name: type multiplicity = default {property-string}

An example of this is:

- name: String [1] = "Untitled" {readOnly}

Only the name is necessary.

· This visibility marker indicates whether the attribute is public (+) or private (-);

· The name of the attribute—how the class refers to the attribute—roughly corresponds to the name of a field in a programming language.

· The type of the attribute indicates a restriction on what kind of object may be placed in the attribute. We can think of this as the type of a field in a programming language.

· The default value is the value for a newly created object if the attribute isn't specified during creation.

· The {property-string} allows us to indicate additional properties for the attribute. In the example, I used {readOnly} to indicate that clients may not modify the property. If this is missing, we can usually assume that the attribute is modifiable. I'll describe other property strings as we go.

Operations are the actions that a class knows to carry out. Operations most obviously correspond to the methods on a class. Normally, we don't show those operations that simply manipulate properties, because they can usually be inferred.

The full UML syntax for operations is:

Visibility name (parameter-list) : return-type {property-string}

· This visibility marker is public (+) or private (-);

· The name is a string.

· The parameter-list is the list of parameters for the operation.

· The return-type is the type of the returned value, if there is one.

· The property-string indicates property values that apply to the given operation.

An example operation on account might be:

+ balanceOn (date: Date) : Money

Visibility allows to constrain the usage of a named element, either in namespaces or in access to the element. It is used with classes, packages, generalizations, element import, package import. UML has the following types of visibility:

  • public (+)

  • package (~)

  • protected (#)

  • private (-)

8. Relationships between classes: definitions, description, examples.

Classes are interrelated to each other in specific ways. In particular, relationships in class diagrams include different types of logical connections.

Association is a broad term that encompasses just about any logical connection or relationship between classes. For example, passenger and airline may be linked as above.

Directed Association refers to a directional relationship represented by a line with an arrowhead. The arrowhead depicts a container-contained directional flow.

Reflexive Association occurs when a class may have multiple functions or responsibilities. For example, a staff working in an airport may be a pilot, aviation engineer, a ticket dispatcher, a guard, or a maintenance crew member. If the maintenance crew member is managed by the aviation engineer there could be a managed by relationship in two instances of the same class.

Aggregation

Folder could contain many files, while each File has exactly one Folder parent. If Folder is deleted, all contained Files are deleted as well.

Multiplicity is the active logical association when the cardinality of a class in relation to another is being depicted. For example, one fleet may include multiple airplanes, while one commercial airplane may contain zero to many passengers. The notation 0..* in the diagram means “zero to many”.Multiplicity is a definition of an inclusive interval of non-negative integers to specify the allowable number of instances of described element.

Hospital has 1 or more Departments, and each Department belongs to exactly one Hospital. If Hospital is closed, so are all of its Departments.

Checking, Savings, and Credit Accounts are generalized by Account. Realization denotes the implementation of the functionality defined in one class by another class. To show the relationship in UML, a broken line with an unfilled solid arrowhead is drawn from the class that defines the functionality to the class that implements the function. In the example, the printing preferences that are set using the printer setup interface are being implemented by the printer.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]