Unified Modeling Language (UML), also known as standard Modeling Language. Is a language for visual modeling of software-intensive systems. The definition of UML includes two elements: UML semantics and UML notation. UML is an open method for illustrating, visualizing, building, and writing artifacts of an object-oriented software-intensive system during development. The best application is engineering practice, where modeling large-scale, complex systems, especially at the software architecture level, has proven effective. Unified Modeling Language (UML) is a modeling language. Most models are presented in the form of diagrams. A typical modeling diagram usually contains several blocks or boxes, connecting lines, and text for additional information about the model. These are simple but important, interlinked and extended in UML rules. The above content is from Baidu Encyclopedia.

ProcessOn, an online tool for drawing and learning, is recommended

A UML class diagram, a type of UML diagram, is a diagram used in object-oriented languages to represent a class. The basic UML class diagram is as follows:

Class simple representation:

As shown in the figure above, it represents a class, with three cells from top to bottom:

  • Class name (italic if interface)
  • Class properties (typically fields and attributes of the class, but not this line)
  • Operations of a class (typically methods or behaviors of a class)

They have the following types of symbols: “+” for public, “-” for private, and “#” for protected

The top UML class diagram represents the following code:

public class Student {
    private String name;
    private String sex;
    private int age;

    public void study(a) {
        System.out.println("study");
    }

    protected void sleep(a) {
        System.out.println("sleep");
    }

    public void eat(a) {
        System.out.println("eat");
    }
// The get and set methods have nothing to do with the attributes of this class
}
Copy the code

Class relational representation:

  1. Inheritance relation (hollow triangle represented by solid line)
public class SeniorSchool extends Student {

    public void graduate(a) {
        System.out.println("Graduation");
    }
    public void cllegeEntranceExam(a) {
        System.out.println("The university entrance exam"); }}Copy the code
  1. Implementation interface (hollow triangle with dotted line)
  • Let senior three learn to play this interface
public interface Play {
    void play(a);
}
Copy the code
public class SeniorSchool extends Student implements Play {

    public void graduate(a) {
        System.out.println("Graduation");
    }

    public void cllegeEntranceExam(a) {
        System.out.println("The university entrance exam");
    }
// Implement interface methods
    @Override
    public void play(a) {
       System.out.println("High school seniors play."); }}Copy the code
  1. Dependencies (represented by dotted arrows) By dependencies, this class can depend on other classes when it is constructed. For example, human beings depend on water and air, students are also human beings, so the following
  • Student has a constructor like this:
/** * A constructor for Student * relies on Air and Water **@param air
     * @param water
     */
    public Student(Air air, Water water) {}Copy the code
  1. Association relationships (represented by solid arrows)

By association, we mean that this class has an attribute that is another class, as shown in the figure and code below.

  • Dormitory class
public class Dormitory {
    private String num;
}
Copy the code
  • Grade one Student
public class PrimaryStudent extends Student {

    private Dormitory dormitory;
}
Copy the code
  • Notice the difference between that and a dependency. Many people think it’s a dependency
  1. Aggregation relationships (represented by hollow diamonds and solid arrows)

    If you look at the code, it’s clear that there are a lot of students in the school, that’s an aggregation relationship. It might be a bit of a hard sell to say this school, but it might be easier to understand it in terms of the student body

public class School {
    private Student[] students;
}
Copy the code
  1. Composition (composition) relationships (represented by solid diamonds and solid arrows)
  • It represents a strong ‘ownership’ relationship, much like the previous dependencies and associations, such as the name,sex, and age attributes in the Stuent class. It is a combination of the name,sex, and age attributes of a Student class, because all three must be present when a Student object is initialized. Although these three types are a basic type, and would be easier to understand if they were a class, “Everything is an object” is barely understandable.
  • To better understand this, let’s give the Student class a combinatorial Book class.

public class Student {
    private Book book;

    public Student(Book book) {
        this.book = book; }}Copy the code

Welcome to follow my wechat public account “Small Fish and Java”.

Finally, paste the whole picture: