当前位置:网站首页>UML class diagram

UML class diagram

2022-06-10 12:25:00 shangzh!

Basic introduction

  1. UML( Unified modeling language ), It is a language tool for software system analysis and design , It is used to help software developers think and record the results of ideas
  2. UML Itself is a set of symbolic regulations , Just like mathematical symbols and chemical symbols , These symbols are used to describe the elements in the software model and the relationship between them , Such as class 、 Interface 、 Realization 、 generalization 、 rely on 、 Combine 、 Polymerization, etc. .
     Insert picture description here

Dependency relationship

  • As long as the other party is used in the class , Then there is a dependency between them . If there's no one else , Can't even compile .

Code instance

public class PersonServiceBean {
    
    private PersonDao personDao; // class 
    public void save(Person person){
     }
    public IDCard geIDCard(Integer personid){
    
        return null;
    }
    public void modify(){
    
        Department department = new Department();
    }
}

public class PersonDao {
    }
public class Person {
    }
public class IDCard {
    }
public class Department {
    }

Class diagram
 Insert picture description here

Summary

  1. Class uses the other side
  2. If it's a member property of a class
  3. If it's the return type of the method
  4. Is the receiving parameter type of the method
  5. Method used in

Generalization relation

  • Generalization is actually inheritance

Code instance

public class DaoSupport {
    
    public void save(Object entity){
    }
    public void delete(Object id){
    }
}

public class PersonServiceBean extends DaoSupport{
    }

Class diagram
 Insert picture description here

Summary

  1. Generalization is actually inheritance
  2. If A Class inherited B class , Then we can say A and B There is a generalization relationship

Realization relationship

  • Realizing a relationship is actually A Class implements the B class

Code instance

public interface PersonService {
    
    public void delete(Integer id);
}

public class PersonServiceBean implements  PersonService{
    
    @Override
    public void delete(Integer id) {
    
        System.out.println("delete...");
    }
}

Class diagram
 Insert picture description here

Connections

  • Association is actually the relationship between classes , The association is navigable , A two-way or one-way relationship , Correlation has multiplicity .

One way one-on-one relationship
Code instance

public  class Person{
    
    private IDCard card;
}

public class  IDCard{
    }

Two way one-on-one relationship
Code instance

public  class Person{
    
    private IDCard card;
}

public class  IDCard{
    
    private Person person;
}

Aggregate relationship

  • An aggregate relationship is a relationship between the whole and the part , The whole and the part can be separated . Aggregation is a special case of association , So it's associated with navigation and multiplicity .
  • Such as : A computer consists of a keyboard (keyboard)、 Monitor (monitor), Mouse, etc , The components of a computer can be separated from the computer , Use a solid line with a hollow diamond center to represent .

Code example

public class Computer {
    
    private  Mouse mouse; // Mouse can and computer Separate 
    private  Moniter moniter; // The monitor can be connected with computer Separate 
    public void setMouse(Mouse mouse){
    
        this.mouse = mouse;
    }
    public void setMoniter(Moniter moniter){
    
        this.moniter = moniter;
    }
}

public class Moniter {
    }
public class Mouse {
    }

Class diagram
 Insert picture description here

synthetic relation

  • Whole and part cannot be separated

Code instance

public class Computer {
    
    private Mouse mouse = new Mouse(); // The mouse cannot be connected with computer Separate 
    private Moniter moniter = new Moniter(); // The monitor cannot be connected with computer Separate 
    public void setMouse(Mouse mouse){
    
        this.mouse = mouse;
    }
    public void setMoniter(Moniter moniter){
    
        this.moniter = moniter;
    }
}

Class diagram
 Insert picture description here

原网站

版权声明
本文为[shangzh!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101216363492.html