UML correct way to eat ---- positive solution! !

In development, the class diagram can reflect the relationship between class and class, is the object (oo) for the development of the most important tools, let's look at the basics of the class diagram

Here Insert Picture Description

  • class
    Here Insert Picture Description
    • The first line, represents the class name, if the class is an abstract class slash
    • The second line shows the class properties, the Person class has two attributes
    • The third line, represents the class methods and behavior
      + is Public, - represent private, # represents a protected
  • interface
    Here Insert Picture Description
    • The first line, represents the interface name
    • The second line shows the attributes of the interface
    • The third line, represents the interface methods and behavior
      + is Public, - represent private, # represents a protected

Relationship @ [toc] between classes and interfaces

Here Insert Picture Description

1. dependencies (Dependence)

A Class B Class uses, in use, is dependent on A B

E.g:

  • IDCard
public class IDCard {

}
  • Person
public class Person {

}
  • PersonDao
public class PersonDao {

}
  • Department
public class Department {

}
  • PersonServiceBean
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();
	}
}
  • It is represented by the class diagram
    Here Insert Picture Description
    Summary:
  1. When the dependence refers to the use of a class in the class, the relationship used to rely
  2. If the property is a member of the class
  3. If the return type
  4. Method of parameter type is received
  5. The method used to

2. generalization (generalization)

  • Generalization is extends, is dependent on the special case
    such as:
  • DaoSupport
public class DaoSupport {
	
	public void save(Object entity){
		
	}
	
	public void delete(Object id){
		
	}

}
  • PersonServiceBean
public class PersonServiceBean extends DaoSupport{

}
  • Represented by the class diagram
    Here Insert Picture Description
    Summary:
  1. Generalization is realized on inheritance
  2. If the A class inherits class B, then A and B exist generalization relationship

3. To achieve the relationship (Implementation)

  • That implements the interface of a class, override the methods of the interface.
    E.g:
  • PersonService【interface】
public interface PersonService {

	public void delete(Integer id);
}
  • PersonServiceBean
public class PersonServiceBean implements PersonService{

	public void delete(Integer id) {
		
	}
}
  • FIG class represents
    Here Insert Picture Description

4. association (Association or)

  • In fact, the link between class and class: such as one to one, one to many

4.1 one-way relationship

  • IDCard
public class IDCard {

}
  • Person
public class Person {
	
	private IDCard card;
	
}
  • The class diagram represents
    Here Insert Picture Description
    4.2 two-way one to one relationship
  • Person
public class Person {
	
	private IDCard card;
	
}
  • IDCard
public class IDCard {
	
	private Person person;
	
}
  • FIG class represents
    Here Insert Picture Description

The aggregation relationship (Aggregation)

  • The polymerization is represented by the global and local, and the whole part can be separated, which is a special relationship, with the associated navigation and multiplicity.
  • Scenario: a computer by keyboard (keyboard), a display (monitor), of a mouse.
  • Monitor
public class Monitor {

}
  • Mouse
public class Mouse{

}
  • Computer
public class Computer {

	private Mouse mouse;
	private Monitor monitor;
	public void setMouse(Mouse mouse){
		this.mouse = mouse;
	}
	public void setMonitor(Monitor monitor){
		this.monitor = monitor;
	}
}
  • FIG class represents
    Here Insert Picture Description

6. A combining relationship (Composition)

  • The relationship between whole and part, but part of the whole and can not be separated.

Scenarios ①:
Person and IDCard, Head, Head and Person combination, IDCard with Person polymerization.

  • Head
public class Head{

}
  • IDCard
public class IDCard {

}
  • Person
public class Person {

    private IDCard card;
    private Head head = new Head();
}
  • Class represented by FIG.
    Here Insert Picture Description

Scenarios ②:
a mouse, a monitor and the computer can not be separated

  • Mouse
public class Mouse{
}
  • monitor
public class Moniter {
}
  • Computer
public class Computer {

    private Mouse mouse = new Mouse();//鼠标 与computer不可分离
    private Moniter moniter = new Moniter();//显示器和computer不可分离

    public void setMouse(Mouse mouse) {
        this.mouse = mouse;
    }

    public void setMoniter(Moniter moniter) {
        this.moniter = moniter;
    }
}
  • FIG form class
    Here Insert Picture Description

These are all relationships between the UML class and class!

Here Insert Picture Description

Published 47 original articles · won praise 34 · views 8866

Guess you like

Origin blog.csdn.net/weixin_42893085/article/details/105266195