table of Contents
- Relationship @ [toc] between classes and interfaces
- 1. dependencies (Dependence)
- 2. generalization (generalization)
- 3. To achieve the relationship (Implementation)
- 4. association (Association or)
- The aggregation relationship (Aggregation)
- 6. A combining relationship (Composition)
- These are all relationships between the UML class and class!
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
- class
- 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
- 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
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
Summary:
- When the dependence refers to the use of a class in the class, the relationship used to rely
- If the property is a member of the class
- If the return type
- Method of parameter type is received
- 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
Summary:
- Generalization is realized on inheritance
- 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
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
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
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
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.
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