[Unfinished] relationships between classes

First, the dependence

A class is assumed that the change causes a change in class B, it means B depends on A.
In the UML diagram, by a broken line arrow indicates a dependency relationship between the classes.
Dependence particular the following three cases.

  • 1, A Class B Class local variables, then, can cause changes in the variant A B, B depends DESCRIPTION A.
  • 2, A is a parameter class class method B, A B changes can cause similar changes.
  • 3, A Class B Class sends a message, so that A can also change B, B can be dependent on said A.
public class Driver {
    
    public void drive(Car car){      //类Car是Driver里一个方法的参数,说明Car的变化能带来Driver的变化,则说明Driver依赖Car
        
        car.move();
    }
}

public class Car {

    public void move() {
    
        ...
    }
}

Second, the generalization (inheritance) relationship

A is B, C of the parent class, A is described B, C generalization.
In the UML diagram, a solid line represents a generalization open triangles. In Java, use extends to implement a generalization relationship.

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() {

        ...
    }
}

Among the UML, there are three requirements for generalization:

  • 1, the subclass should be identical to the parent, the parent class has attributes, operations, should all have subclasses.
  • 2, in addition to the subclasses of the parent class information is consistent, further comprising additional information.
  • 3, the local instance of the parent class can also be used in the instance of a subclass.

Third, the relationship

Between class association, such as customers and orders, a customer has a lot of orders, an order corresponding to a client, which say there is a correlation between them.
In UML, association using solid lines to connect to
associate, typically a class object as an attribute of another class

  • 1, two-way association
    you have me I have you.
public class Customer {

    private Product [] products;
    
}

public class Product {
    
    private Customer customer;
}
  • 2, associated with one-way
    only one class to another class attribute as
    indicated by solid arrow way.
  • 3, since the correlation
    properties of some classes of object types for himself
  • 4, the number of re-association: a class object represents the number of object classes connected to the other

    1..1 represents an object of another class is only associated with a class object
    0 .. * denotes an object of another class with zero or more objects related class
    1 .. * represents another class an object class object with one or more related
    0..1 represents an object of another class or not related to only one class object
    m..n represents an object of another class and a minimum m, most n the object has a relationship

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

public class Button {
    ...
}

Fourth, the aggregation relationship

And part of an overall relationship. Usually in the definition of a whole class, go to analyze the composition of the structure of the whole class, to find out the members of the class, the formation of aggregation relationship between the class and the members of the class as a whole. In the aggregation relationship, the members of the class is part of the whole class, i.e., a member of the object is an integral part of the object, but the object may be a member integrally from objects exist independently.
In the UML diagram, open diamond belt syndication relationship expressed by a line

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

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

public class Engine {
    ...    
}

Fifth, the combination relationship

That is part of the whole and relationships, but as a whole and not separate section. And part of a unified whole lifetime, once the whole object does not exist, will also be part of the object does not exist. With the total death.
In UML, the linear relationship used in combination with solid diamond indicates.

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

public class Mouth {
...
}

Sixth, realization relationship

Used to define the class interface and implementation or interface structure build relationships, the interface is a set of operations, but these operations for specifying a service class or constructed.
Here did not learn the interface, first put off

Guess you like

Origin www.cnblogs.com/hmzmua/p/10991830.html