Design Mode Study Note 1: UML class diagram

Source: Internet
Author: User
Design Mode Study Note 1: UML class diagram

The UML class diagram is the basis for learning the design pattern. Through the UML class diagram, you can better communicate with everyone and easily express your own design ideas. It is like Mandarin, is a standard language.

Currently, there are two popular tools: Rational Rose and Microsoft Visio, both of which are easy to use. You can choose which one is your preferred one. I like Microsoft software, so Microsoft Visio 2003 is my first choice.

Class:

A rectangular box represents a class (-1). A class chart is divided into three layers. The first layer is the class name. If it is an abstract class name, it is indicated in italics, as shown in the animal class. The second layer is the characteristics of the class (usually the fields and attributes of the class ). The third layer is a class operation (usually a method or action ). Note that the preceding symbol "+" indicates public, "-" indicates private, and "#" indicates protected.


(Figure-1)

An animal class is an abstract class. It cannot be instantiated, while a swine class can be instantiated.

Interface:

Interfaces can be represented in two ways: rectangular notation (the flying interface in-2) and lollipop notation (the interface for talking people in the Tang Lao duck class in-2 ). Rectangular representation, with <interface> or <interface> at the top. Line 1: Interface Name, line 2: interface method. Lollipop notation. The interface name is next to the circle, and the interface method appears in the implementation class, such as the speech in the Tang Lao duck class.


(Figure-2)

Generalization(Generalization)

Represents the inheritance relationship between classes, the inheritance relationship between interfaces, or the Implementation relationship between classes on interfaces. The general relationship is directed from the subclass to the parent class, which is opposite to the inherited or implemented method. Specific manifestation: parent class instance = new subclass ();


(Figure-3)

(Figure-4)

Use a hollow triangle + solid line to represent inheritance (-3 ). In the static structure diagram, drag and drop between the parent class and the Child class to link them. The arrow points to the parent class, and the other part points to the Child class. Associations are implemented using instance variables.

Use a hollow triangle + dotted line to represent the implementation interface (-4 ). In the static structure, right-click any class shape ("class", "parameterized class", "utility", or "Meta class"), and click "shape display options ", select "implementation link" under "general options ". Attaches the control handle (a small yellow-colored diamond) of the Implementation link in the class shape to the connection point of the interface, class, or other elements.

Association)

For two relatively independent objects, when the instance of one object has a fixed ing relationship with some specific instances of the other object, the two objects are associated. Association is divided into two-way Association, one-way Association, and self-Association.

Two-way Association: two-way Association is the connection between two classes. Associations are always assumed to be two-way; this means that the two classes know the relationship between them unless you limit some other types of associations. The flight example (figure-5) shows a standard type association between the flight class and the plane class.

 
(Figure-5)

A bidirectional Association is represented by a solid line between two classes. At any end of the line, you place a role name and multiple values. Figure 5 shows that flight is associated with a specific plane, and the flight class knows this association. Because the role name is represented by the plane class, plane assumes the "assignedplane" role in the association. The multi-value description 0 following the plane class... 1 indicates that when a flight object exists, there can be one or no plane associated with it (that is, plane may not be allocated ). Figure 5 also shows that plane knows its association with the flight class. In this association, flight assumes the "assignedflights" role; figure-5 shows that plane entities can be not associated with flight (for example, it is a brand new aircraft) or associated with an unlimited flight (for example, an airplane that has been in service for 5 years.

I am confused about the descriptions of multiple values that may occur at the end of the association. Some examples of multiple values and their meanings are listed below (0 .. 1-0 or 1; 1: only 1; 0 .. *: 0 or more; *: 0 or more; 1 .. *: one or more; and so on .)

Single join: In a one-way join, two classes are related, but only one class knows the existence of this association. (Figure-6) shows an instance of one-way associated overdraft financial report.


(Figure-6)

A unidirectional Association is a solid line with an open arrow pointing to a known class (an unclosed arrow or triangle for flag inheritance. As with standard associations, one-way associations include a role name and a multi-value description. However, if they are different from standard bidirectional associations, one-way associations only contain the role names and multi-value descriptions of known classes. In the example (figure-6), overdrawnaccountsreport knows the bankaccount class and knows that the bankaccount class assumes the "overdrawnaccounts" role. However, unlike the Standard Association, The bankaccount class does not know that it is associated with overdrawnaccountsreport.

Dependency (Dependency)

For two relatively independent objects, when one object is responsible for constructing an instance of another object or dependent on the service of another object, the two objects are mainly dependent on each other. Dependencies are embodied in local variables, method parameters, and calls to static methods. For example, animals have several major features, such as metabolism, reproduction, and life. To make animals alive, they need oxygen, water, and food. That is to say, animals depend on oxygen and water. They are dependent on each other, expressed by a virtual arrow. See Figure 7.


(Figure-7)

Class Diagram code:

Abstract class animal

{

Public String metabolism (oxygen, water)

{

}

}

Aggregation)

An aggregation relationship indicates a weak property relationship. Object A can have object B, but object B is not part of object. The aggregation relationship is expressed by hollow diamond and solid arrow. As shown in Figure 8:


(Figure-8)

Logically, there are cars in the parking lot, but the car is not part of the parking lot. There is no relationship between the vehicle and the parking lot.

Composition)

Combination also becomes a combination and synthesis relationship. It is a strong "ownership" relationship, reflecting the strict relationship between the part and the whole, and the same as the overall life cycle. As shown in Figure 9, the wings of a bird and a bird are a combination (synthetic) relationship. They are the relationship between the part and the whole, and the wings and the life cycle of a bird are the same. The compositing relationship is expressed by solid diamond and solid arrows. There is a number at both ends of the Link (figure-9). The numbers '1' and '2' are used as the base. It indicates that the class at this end can have several instances. Obviously, a bird has only two wings. If a class can have multiple instances, it is represented by 'n. You can also use the base number for the Association and aggregation relationships.


(Figure-9)

In a strict combination (synthesis) relationship, there is a strong dependency between classes. In many cases, Objects representing the whole must be responsible for keeping some objects alive.
References: big talk Design Mode

Tag: design mode, UML class diagram posted @ 2008-05-29 peida read (603) Comments (2) EDIT favorite category: Design Mode

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.