JAVA GOF of 23 kinds of common design patterns summarized relationships between classes in FIG. 02 UML class diagram and

Unified Modeling Language (UML)

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, defined by case diagram, class diagram, an object diagram, a state diagram, an activity diagram, a timing diagram, a collaboration diagram, FIG member, FIG deployment nine kinds of 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. Class names: for example, students in class Student
  2. Properties: is the class member variables: naming   [visibility] attribute name: type [= default]
  3. Visibility: represents an element outside the attribute class is visible, including the public (Public), private (Private), protected (Protected) and friends (Friendly) 4 species in the class diagram, respectively, by the symbol +, -, # ~ represents.
  4. Operation: The method of any class is: UML format:  [visibility] name (parameter list) [: Return Type]

 

UML represents the student class, four private member variables, as well as a public method to display ()

 

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.

Graph Interface defines a method and defines the two subclasses must implement the inheritance

 

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.

 

 

 As shown, defines a Graph interface, and there are two rectangular and circular subclasses to achieve it, and with respect to the inside of the method is achieved, then there is an access Client class, there is a method in which it Graph of parameters, it can use this parameter to call

Corresponding to the following sub-method type, functional

The relationship between class and class

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.

Coupling sorting, were enhanced

  1. Dependencies
  2. connection relation
    • General association
    • Aggregation relationship
    • Combination of relationship
  3. Generalization
  4. Realization relationship

 

1. Dependencies

Dependent (the Dependency) relationship is a relationship to use, which is the weakest coupling between objects in an association manner, a temporary association. In the code, a method of a class by a local variable,

Certain method parameters or method calls to the static method to access another class (the dependent class) to complete some of the responsibilities.

 

As shown, the dotted arrow shows the use of dependencies, points to the class using the class dependent, as shown, inside the human class method call a call (), and a phone call which has the properties of class

People like to call the following phone type of transfer () method

 

2. relationship

Association (Association) relationship is a relationship between the object reference, is used to represent a kind of link between the object and the object of another class, such as teacher and student, master and apprentice, husband and wife and so on.

关联关系是类与类之间最常用的一种关系,分为一般关联关系、聚合关系和组合关系。我们先介绍一般关联。

 

关联可以是双向的,也可以是单向的。在 UML 类图中,双向的关联可以用带两个箭头或者没有箭头的实线来表示,

单向的关联用带一个箭头的实线来表示,箭头从使用类指向被关联的类。

如图所示,一个老师有多个学生,而一个学生也可以有多个老师,他们进行了一个双向的关联。

使用类指向被关联的类

3.聚合关系

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

 

 

 聚合关系可以用带线的空心菱形来表示,菱形指向整体

 4.组合关系

 

组合(Composition)关系也是关联关系的一种,也表示类之间的整体与部分的关系,但它是一种更强烈的聚合关系,是 cxmtains-a 关系。
 
在组合关系中,整体对象可以控制部分对象的生命周期,一旦整体对象不存在,部分对象也将不存在,部分对象不能脱离整体对象而存在。

 

例如,头和嘴的关系,没有了头,嘴也就不存在了。

组合关系用带实心菱形的实线来表示,菱形指向整体。

 

 5.泛化关系

泛化(Generalization)关系是对象之间耦合度最大的一种关系,表示一般与特殊的关系,是父类与子类之间的关系,是一种继承关系,是 is-a 的关系。

在 UML 类图中,泛化关系用带空心三角箭头的实线来表示,箭头从子类指向父类。在代码实现时,使用面向对象的继承机制来实现泛化关系。

 

 6.实现关系

实现(Realization)关系是接口与实现类之间的关系。在这种关系中,类实现了接口,类中的操作实现了接口中所声明的所有的抽象操作。

实现关系使用带空心三角箭头的虚线来表示,箭头从实现类指向接口。

 

 

 

 参考文档:23种设计模式UML教程

 

Guess you like

Origin www.cnblogs.com/ChromeT/p/11005154.html