The relationship between the UML class diagram and FIG class

Introduction to the Unified Modeling Language

Unified Modeling Language (Unified Modeling Language, UML) is a visual modeling language used to design software blueprint in 1997 by Object Management Group (OMG) adopted as the international standard modeling language for object-oriented. It is characterized by a simple, unified, graphical, software design can express dynamic and static information.

Unified Modeling Language provides modeling and visualization support for all phases of software development. Also integrated into the new ideas, new methods and new technologies in the field of software engineering, software designers to make communication more concise, further reducing design time, reduce development costs. Its application is very wide, not only for the development of a general system, and adapted for Parallel and Distributed Systems Modeling.

UML target systems from different angles of view, defines a use case diagram, class diagram, an object diagram, a state diagram, an activity diagram, a timing diagram, a collaboration diagram, FIG member, nine kinds of FIG deployment FIG.


Classes, interfaces and classes FIG.

1. Class

Class (Class) means having the same properties, methods and relationships abstract object that encapsulates the behavior and data is the basis for object-oriented programming (OOP), and having encapsulation, inheritance and polymorphism three characteristics . In UML class containing a class name, attributes, and operations and dividers are represented with a rectangle.

(1) the class name (Name) is a string, e.g., Student.

(2) Properties (the Attribute) refers to the attribute class, i.e. the class member variable. UML representation in the following format:

[Visibility] Name attribute: Type [= default]

For example: -name: String

Note: "Visibility" represents an element outside the class attribute is visible, including the public (Public), private (Private), protected (Protected) and friends (Friendly) 4 species in the class of FIG. respectively by symbol +, -, #, ~ Fig.

(3) Operation (the Operations) is one example of the behavior of any object class can be used, is a member of the class method. UML representation in the following format:

[Visibility] name (parameter list) [: Return Type]

For example: + display (): void.

Figure 1 shows the class students UML representation.

Student category
FIG 1 Student Class

2. Interface

Interface (Interface) is a special class, but having a structure of the class can not be instantiated, can only be achieved by subclasses. It contains the abstract operation, but does not contain the property. It describes the class of external visible components or operation. In UML, interface with the name of a small circle to FIG.

It is a graphical class interface shown in Fig. 2 UMDL FIG.


2 Graph Interface FIG.

Class 3. FIG.

FIG class (the ClassDiagram) system is used to display the classes, interfaces, and to a static model collaboration static structure and the relationship between them. It is mainly used to structure software systems design description to help people simplify the understanding of the software system, which is an important product of systems analysis and design phase, it is an important model system based on coding and testing.

FIG class classes can be directly implemented by a programming language. The class diagram in the entire life cycle of software development are effective, it is modeling object-oriented systems of most common map. As shown in FIG. 3 is a "calculated rectangular and circular perimeter and area" class diagram, the graphical interface has an abstract method for calculating area and perimeter, rectangular and circular achieve these two methods for accessing class calls.

"Calculation of rectangular and circular perimeter area" in FIG class
FIG. 3 "is calculated and rounded rectangular perimeter with the area of" Class FIG.

Relations between classes

In software systems, like not exist in isolation, there are various relationships between classes. The degree of coupling between the classes and the classes are arranged from weak to strong, the UML class diagram are the following relation: dependency relationship, the relationship between the polymerization, combination relation, and to achieve generalization relationship. Wherein the coupling degree of generalization and implementation are equal, they are the strongest.

1. Dependencies

依赖(Dependency)关系是一种使用关系,它是对象之间耦合度最弱的一种关联方式,是临时性的关联。在代码中,某个类的方法通过局部变量、方法的参数或者对静态方法的调用来访问另一个类(被依赖类)中的某些方法来完成一些职责。

在 UML 类图中,依赖关系使用带箭头的虚线来表示,箭头从使用类指向被依赖的类。图 4 所示是人与手机的关系图,人通过手机的语音传送方法打电话。

Examples of dependency
图4 依赖关系的实例

2. 关联关系

关联(Association)关系是对象之间的一种引用关系,用于表示一类对象与另一类对象之间的联系,如老师和学生、师傅和徒弟、丈夫和妻子等。关联关系是类与类之间最常用的一种关系,分为一般关联关系、聚合关系和组合关系。我们先介绍一般关联。

关联可以是双向的,也可以是单向的。在 UML 类图中,双向的关联可以用带两个箭头或者没有箭头的实线来表示,单向的关联用带一个箭头的实线来表示,箭头从使用类指向被关联的类。也可以在关联线的两端标注角色名,代表两种不同的角色。

在代码中通常将一个类的对象作为另一个类的成员变量来实现关联关系。图 5 所示是老师和学生的关系图,每个老师可以教多个学生,每个学生也可向多个老师学,他们是双向关联。

Examples of affiliated
图5 关联关系的实例

3. 聚合关系

聚合(Aggregation)关系是关联关系的一种,是强关联关系,是整体和部分之间的关系,是 has-a 的关系。

聚合关系也是通过成员对象来实现的,其中成员对象是整体对象的一部分,但是成员对象可以脱离整体对象而独立存在。例如,学校与老师的关系,学校包含老师,但如果学校停办了,老师依然存在。

在 UML 类图中,聚合关系可以用带空心菱形的实线来表示,菱形指向整体。图 6 所示是大学和教师的关系图。

Examples of the polymerization relationship
图6 聚合关系的实例

4.组合关系

Composition (Composition) relationship is also associated with a relationship, but also shows the relationship between whole-part type, but it is a stronger relationship between the polymerization is cxmtains-a relationship.

Relationship in the combination, the control object may be the entire lifecycle of the object, once the whole object does not exist, will also be part of the object does not exist, the entire portion of the object from the objects can not exist. For example, the relationship between the head and mouth, not his head, mouth would not exist.

In UML class diagram, the relationship between the combination with a solid line with solid diamonds represented, the whole diamond points. Figure 7 is a graph of the head and mouth.

Examples of combinations relations
Example 7 FIG combination relation

5. Generalization

Generalization (the Generalization) relationship is a relationship of the maximum degree of coupling between objects, and shows the general special relationship, the relationship between parent and child classes, that is an inheritance, the is-a relationship.

In UML class diagram, a solid line with generalization hollow triangular arrow represented, an arrow pointing from the subclass parent class. When code is implemented using object-oriented inheritance mechanism to achieve generalization. For example, Student classes are classes and subclasses Teacher Person class, which class diagram shown in Fig.

Examples of generalization
Example 8 FIG generalization

6. Implement relations

Implement (Realization) relationship is between the interface and implementation class. In this relationship, the class implements an interface, operating class implements all the abstract operation interface declared.

In UML class diagram, with dashed lines to achieve the relationship represented hollow triangular arrow, arrows pointing from the class that implements the interface. For example, automotive vehicles and boats realized that the class diagram shown in Fig.

Examples of realized relations
Examples 9 to achieve the relationship of FIG.

Guess you like

Origin www.cnblogs.com/sallyiszxm/p/10979600.html