Unified Modeling Language (UML)
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.
- Class names: for example, students in class Student
- Properties: is the class member variables: naming [visibility] attribute name: type [= default]
- 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.
- 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
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
- Dependencies
- connection relation
- General association
- Aggregation relationship
- Combination of relationship
- Generalization
- 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.聚合关系
聚合关系可以用带线的空心菱形来表示,菱形指向整体
4.组合关系
例如,头和嘴的关系,没有了头,嘴也就不存在了。
组合关系用带实心菱形的实线来表示,菱形指向整体。
5.泛化关系
泛化(Generalization)关系是对象之间耦合度最大的一种关系,表示一般与特殊的关系,是父类与子类之间的关系,是一种继承关系,是 is-a 的关系。
在 UML 类图中,泛化关系用带空心三角箭头的实线来表示,箭头从子类指向父类。在代码实现时,使用面向对象的继承机制来实现泛化关系。
6.实现关系
实现(Realization)关系是接口与实现类之间的关系。在这种关系中,类实现了接口,类中的操作实现了接口中所声明的所有的抽象操作。
实现关系使用带空心三角箭头的虚线来表示,箭头从实现类指向接口。
参考文档:23种设计模式UML教程