Design pattern 0. Introduction to UML

0. Introduction to UML

UML class diagram and corresponding code:

represents the definition of a class Employee, including the attributes name, age and email and operation modifyInfo()

public class Employee {
    
    
    private String name;
    private int age;
    private String email;
    
    public void modifyInfo() {
    
    }
}

UML interface and corresponding code:

public interface Vehicle {
    
    
    public void move();
}

The representation of UML attributes is:
visibility name: type [=default value]

where + means public,-means private, # means protected

UML operation is expressed as:
visibility name ([parameter list])=[:return type]

UML represents the two-way relationship of classes:

public class Customer {
    
    
    private Product[] products;
}

public class Product {
    
    
    private Customer customer;
}

UML represents the one-way relationship of classes:

public class LoginForm {
    
    
    private JButton loginButton;
}
public class JButton {
    
    }

UML represents the self-association relationship of the class:

public class Node {
    
    
    private Node subNode;
}

UML represents the multiple relationship of

classes : mainly the relationship between another class and this class, and the other class far away from the text

For example: an interface (Form) can have another or more buttons (Button), a button can only belong to one interface

public class Form {
    
    
    private Button[] buttons;
}
public class Button {
    
    }

UML represents the aggregation relationship:

public class Car {
    
    
    private Engine engine;
    public Car(Engine engine) {
    
    
        this.engine = engine;
    }
    public void setEngine(Engine engine) {
    
    
        this.engine = engine;
    }
}
public class Engine {
    
    }

The composition relationship of UML:

public class Head {
    
    
    private Mouth mouth;
    public Head() {
    
    
        mouth = new Mouth();
    }
}
public class Mouth {
    
    }

UML dependencies:

public class Driver {
    
    
    public void drive(Car car) {
    
    
        car.move();
    }
}
public class Car {
    
    
    public void move() {
    
    }
}

The generalization relationship of UML:

public class Person {
    
    
    protected String name;
    protected int age;
    public void move() {
    
    }
    public void say() {
    
    }
}
public class Student extends Person {
    
    
    private String studentNo;
    public void study() {
    
    }
}
public class Teacher extends Person {
    
    
    private String TeacherNo;
    public void teach() {
    
    }
}

UML represents the relationship between interface and implementation:

public interface Vehicle {
    
    
    public void move();
}
public class Ship implements Vehicle {
    
    
    public void move() {
    
    }
}
public class Car implements Vehicle {
    
    
    public void move() {
    
    }
}

Guess you like

Origin blog.csdn.net/u011703187/article/details/104976518