[Java Design Patterns] Summary of the Six Relationships of UML Class Diagrams

[Java design pattern] UML class diagram six relations summary (including code)

1.UML Class Diagrams. Basic introduction to UML

UML is a language tool for software system analysis and design, it is used to help software developers think and record the results of their ideas
Class represents a class
Interface means interface
Dependency means dependency
Association means association
Generalization means generalization (inheritance)
Realization means realization
Aggregation means aggregation
Composite means combination

2..UML Class Diagrams. UML diagram

UML diagrams are divided into static structure diagrams and dynamic behavior diagrams, in which class diagrams describe the relationship between classes and are the core part of UML diagrams, so we mainly learn and introduce class diagrams.

Three, UML class diagram
Used to describe the composition of classes (objects) themselves in the system and various static relationships between classes (objects)
Relationships between classes: dependency, generalization (inheritance), implementation, association, aggregation, composition
Four, class diagram classification
As long as the other party is used in the class, there is a dependency between them; if there is no other party, even the compilation will not pass.

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

Corresponding class diagram

The counterparty is used in the class, which can be the member attribute of the class, the return type of the method, and the parameter type received by the method.

A generalization relationship is actually an inheritance relationship, which is a special case of a dependency relationship.

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

Corresponding class diagram

The generalization relationship is actually the inheritance relationship; if class A inherits class B, it is said that there is a generalization relationship between A and B

implementation relationship is actually that class A implements the interface B, which is a special case of the dependency relationship.

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

Corresponding class diagram

The implementation relationship is actually the implementation of the interface; if class A implements the B interface, it is said that there is an implementation relationship between A and B

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us