The basic concept of the class diagram in the third chapter of UML Essence

Source: Internet
Author: User

Chapter III Class Diagrams: Basic Concepts
class DiagramCan be used to describe the types of objects in a system, or to depict a variety of static relationships between objects. In addition, class diagrams can also show the properties and operations of the class (operation), as well as some restrictions (constraint) that can be applied to the way the objects are connected to each other. In UML, we use the feature (feature) to represent the nature and operation of the two concepts of fatigue.
1. NatureThe properties represent the structural properties of the Class (structural feature). Although it is only a concept, it can be rendered in two very different representations: attributes and associations. 2. PropertiesThe attribute (attributes) notation uses a line of text in the four squares of the category to represent the nature. The complete syntax is as follows: Visibility name: Type multiplicity = preset value {nature-string} such as:-name:string [1] = "Untitled" {readonly}
Throughout the syntax, only the "name" section is necessary. (1) The visibility flag indicates that the attribute is public, private, or protect. (2) The name of the property is approximately equivalent to the name in the program language-it shows how the class refers to this property. (3) The type of the attribute represents a restriction that explains exactly which object can be placed in the attribute. (4) About multiplicity (multiplicity), explain it later. (5) The default value indicates that in the newly generated object, if no value is specified for this property during the generation, then we assign the value to the attribute. (6) {nature-string} allows you to indicate some additional properties of this property.
3. AssociationAnother notation of nature is association. The information that can be represented in a property is almost always represented in the association.
The association is represented by a solid line in two categories, and the arrow has a source class pointing to the target class. The name of the property appears on the target side of the association, plus its multiplicity. The class to which the associated target ends are connected is the form of this nature.
Generally, it tends to use attributes on small things, such as dates or Boolean values, and they are usually value-form things. On the other hand, I'm going to use correlations on classes that have significant significance, such as customers or orders. At the same time, it is also inclined to use class four square to draw a class with significant significance, which will also lead to the use of associations; On the other hand, I will represent unimportant things as attributes. This choice was made primarily in order to emphasize the focus.
4. The multiplicity of multiple properties represents how many objects it may be present. The general argument is that we can define multiplicity with a cap and a lower limit. The preset multiplicity of attributes is "1". Although this rule exists in the hyper-model of UML, we cannot assume that the multiplicity is "1" if a property in the graph does not identify multiple attributes, because the multiplicity information can be hidden.
5, bidirectional Association Bidirectional Association represents a pair of properties, they are connected to each other from different directions. Such as:
The Car class has the property owner:person[1], and the person class has the property cars:car[*].
6, the operation of the operation is the class know how to achieve some of the action. Obviously, an operation is a method in a class.
In UML, the complete syntax for operations is: Visibility name (parameter list): return type {nature-string} (1) Visibility is public, private, or protect (2) name is a string (3) A parameter list is a string of parameters (4) that the operation will use to return the type (5) Nature-the string represents some of the property values that can be applied to this operation.
Parameters in a parameter list are represented in a way that is similar to a property. Its syntax is as follows: directionality name: pattern = preset value (1) The name, shape and default value are the same as in the attribute. (2) directionality is used for input (in), output (out), or output (inout) parameters.
Commentary: It is useful to differentiate between actions that change and do not change the state of a class.
The UML defines query as a procedure that takes only the values from the class and does not change the state of the system. It also says that it does not produce side effects. You can do this, plus the {query} character string. Also, I like to change the state of the Operation plus modifiers (modified) character characters.
Action refers to something that we can exhale--it represents the program declaration, and the method is the program ontology. There is a big difference between these two things when there are multiple types. For example: If you have a base class and three subclasses, each subclass overrides the GetPrice operation of the base class. At this time, we have an operation, four methods.
7, the generalized relationship to the generalized relationship is clearly interpreted as inheritance (inheritance). In the mainstream object-oriented language, subclasses inherit all class attributes of the superclass (superclass) and may overwrite methods of any superclass.
8. Dependencies       If the definition of an element may affect other elements, then there is a dependency between the two elements. There are several reasons for the dependency of a class: A class transmits a message to another class; Another class is treated as a piece of data; A class treats another class as a parameter in a method.         If the system continues to grow, you have to worry more and more about any of the control dependencies. If you have no control over dependencies, then any changes we make to the system will cause ripples and make more and more things change.   Table 1 This book is carefully selected for some useful dependency keywords:
Key words Significance
Pager The source element goes back to an operation that invokes the target element
Create The source element produces an instance of the target element
Derive The source element is derived from the target element.
Instantiate SOURCE element is an instance of the target element
Permit The target element allows the source element to access the private attribute in the target element.
Realize The source element is the implementation of the specification or interface defined in the target element
Refine Adornments represent the relationships between different semantic hierarchies.
Substiute The source element is an alternative to the target element.
Trace We use this dependency to track things such as dependencies from requirements to classes, or how changes in a model are practiced in other models.
Use The target element to be used when the source element is implemented

The general principle is to minimize dependencies, especially when dependencies are flooding a large area of the system. It is also important to note that we should be careful to avoid cyclic dependencies, as it can lead to cyclic changes.

9. The restriction rules UML allows us to use anything to describe limitations. The only rule is: put the limit in curly braces {}. One option is to put the name on the front, followed by a colon, like this {No incest: spouses cannot be brothers and sisters} when naming for restrictions.
10, when to use class Diagram class diagram is the backbone of UML, so you can find that they are available at any time. The biggest trouble with class diagrams is that they contain too many things. So they may be overused. Here are some tips to use:
A, do not try to use all the notation that can be used. Let's start with some of the things that are mentioned in this chapter: categories, associations, attributes, generalized relationships and limitations, and so on. As for advanced things, use them only when you feel you need them.
B, I found that conceptual class diagrams are especially useful for exploring the domain language of an enterprise. When you want to do this, you have to try not to discuss the software itself, but to use a very simple notation whenever possible.
C, don't draw a model that contains everything. Instead, focus on the key points. Holding a number of commonly used to, constantly updated figures, compared to holding a lot of forgotten, outdated diagram is OK.
The biggest danger of using class diagrams is that you may over-focus the structure and ignore the behavior in the system.

The basic concept of the class diagram in the third chapter of UML Essence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.