[UML] Detailed explanation of UML class diagram

Table of contents

1 Overview

2. Permissions

3. Relationship

3.1. Connection relationship

3.2. Dependency

3.3. Generalization (inheritance)

3.4. Implementation

3.5. Association

3.6. Aggregation

3.7. Combination


1 Overview

What is UML? In written terms it is:

UML (Unified Modeling Language), Unified Modeling Language, is a standard graphical modeling language for software engineering and system design. It is designed to help developers, designers, and analysts better understand, design, communicate, and document systems during software development. UML provides a set of graphical symbols and rules that can be used to represent all aspects of a software system, from requirements analysis to system design, implementation, and testing.

To put it bluntly:

UML uses graphics and symbols to help describe software systems, making it easier for people to understand what the entire system looks like.

As we know, a software system is a very large and complex thing. If you want to describe it clearly, it is definitely impossible to describe it accurately in one dimension. Therefore, UML proposes a series of diagrams from several dimensions and each dimension used to describe software systems, including:

  1. use case diagram
  2. static structure
    1. Class Diagram
    2. Component Diagram
    3. deployment diagram
  3. dynamic behavior
    1. State diagram
    2. activity diagram
    3. Timing diagram

The above diagrams are frequently used in the standardized description of various types of software systems, but they may not always be used. It is enough to select the required diagrams to describe the system clearly. Among them, the UML class diagram is the most commonly used, because describing the relationship between classes is to describe the relationship between entities. In today's object-oriented design and programming-based system development, this is the foundation of the foundation. This article will first talk about UML class diagrams, and the next article will talk about other diagrams together.

In summary, UML class diagrams provide a set of graphics and symbol standards to describe the relationships between classes in the system, as well as their attributes and methods.

2. Permissions

UML class diagrams describe access rights in a symbolic way, with the following rights:

permissions symbol illustrate
public + public, this attribute is visible to all classes

protected

#

protected, visible to descendants of the class

private 

- Private, visible only to the class itself

package

~

package, only visible to other classes declared in the same package

3. Relationship

3.1. Connection relationship

3.2. Dependency

When class B is used in class A, there is a dependency relationship between A and B. The following is an example of calling dao in a common service:

public class UserServiceImpl{

    private UserDao userDao;

    public User queryById(int id) {return null;}
}

3.3. Generalization (inheritance)

Generalization actually refers to the relationship of is a, A is a B, and the relationship between A and B is a generalization relationship. In object-oriented programming, only inheritance can achieve this effect, so generalization can be understood as inheritance.

public class BaseDao {
    protected void insert(User user){};
    protected void delete(User user){};
    protected void update(User user){};
    protected void query(User user){};
}
public class UserDao extends BaseDao{
    User queryById(int id){
        return null;
    }
}

3.4. Implementation

Implementation is a special case of inheritance:

interface:

public interface UserService {
    User queryById(int id);
}

 Implementation class:

public class UserServiceImpl implements UserService{
    private UserDao userDao;

    @Override
    public User queryById(int id) {
        return userDao.queryById(id);
    }
}

3.5. Association

Association relationship, that is, the connection between classes, is a special case of dependency relationship.

This is an association relationship:

 Why is it a special case of dependency relationship? Because to realize a driver driving a car, then the driver class must hold a car object, that is, rely on a car. In fact, the association relationship can also be replaced by the arrow of the dependency relationship, but it is only expressed by the association relationship, which can describe the relationship of the entity in the business more clearly, so whether to use the dependency relationship or the association relationship to express it depends on the specific situation.

3.6. Aggregation

 Aggregation relationship is a special case of dependency relationship. Dependencies can be separated, that is, the dependent class and the dependent class live and die together differently, that is to say, the entity of the dependent class needs to be imported from the outside world.

3.7. Combination

The composition relationship is a special case of the dependency relationship. The dependencies cannot be separated, that is, the dependent class and the dependent class live and die together, that is to say, the entity of the dependent class will live and die inside the dependent entity. imported from outside.

 

 

Guess you like

Origin blog.csdn.net/Joker_ZJN/article/details/132418191