[Excerpt from Java Developer Frenzied] The relationship is the connection between things. There are four important relationships between classes: dependence, generalization, correlation and implementation. These relationships can be mapped to the code.
Dependencies are a relationship that describes a variation of a specification of a thing may affect another thing that uses it (vice versa). The UML is represented as a dashed line that points to the dependency. There are many constitutive styles, but it is generally not needed to avoid over-complex. In fact, the other three relationships, the associations and implementations can be counted as some dependency, but they have a stronger semantic and important role, so it is divided. Generally, when modeling is modeled, the generalization, association, and realizing modeling, and the rest can be regarded as dependent. Corresponding to the code, there may be many forms, such as public class a {public B Getb (C, D D) {e e = new e (); B b = new b (C, D, E); }} The class A is dependent on class B (method return class), C and D (parameter class), E (method within the method within the variable), because these class changes may affect class A
Ultrafining is a general matter (called superclass or parent class) and a special transaction (called subclass), which is generally inherited for classes, such as: public class a extends B. The general line with a hollow arrow is generally used to represent the general line.
Association is a structural relationship that an object of a thing is associated with an object of another thing. Given a connection to two types of associations, you can navigate to another class from a class object. Generally, the associated painting is generally connected to a solid line of the same or different classes. The association can have a direction, namely navigation. When the navigation is not described, navigation is two-way, and the arrow is not required online. In most cases, navigation is one-way, you can add an arrow. The association is generally expressed in the code as an attribute, such as the public class a {private b b;} can be considered to have an association between B. If B is also associated with A, they are two-way associations. Sometimes b is not the properties of A, but you can also relevant links, for example: public class a {public b [] getbs () {...}} method getbs may go to check the database, find the association between A and B relationship. The simple association between the two classes expressed the structural relationship between two equivalent status classes. Aggregation is also an association relationship. Unlike simple associations, it describes the relationship between a whole and components, ie "HAS-A" relationship, meaning that the overall object has partial objects, such as schools and students. The overall and part of the aggregate does not have an inevitable connection between life cycles, and some objects can be created before the overall object is created, or it can be destroyed after the overall object is destroyed. The polymerization is represented by a solid line with a hollow rhombus (one end). Public class person {...} public class school {private arraylist student (Person Person) {students.add (person);}} combination is a more aggregated correlation form. The combination refers to the form of polymerization associated with a strong relationship and a partial lifecycle. For example, Windows windows and menus on the window are combined relationships. The life cycle is consistent, and the part must be created in combination or afterwards, or destroyed before or at the same time, the partial lifecycle will not exceed the combined life cycle. The combination is expressed in a solid line with solid rhizome. Public Class Menu {...} PUBLIC CLASS WINDOW {Private Menu Menu;} Combination and aggregation In the code implementation of the code implementation is on the implementation of life cycle, the composition needs to be responsible for the creation and destruction of its part. Public class school {public school () {...} // does not need to create any Person objects, and its Students are existing person object public void design () {...} // only need to turn off the School object and Disconnect it with your own Person object, Person object is not destroyed} public class window {private menu Menu; public window () {menu = new menu ();} // can be created at this time MENU object, or then create public void destory () {menu.destory ();} // must or destroy the associated MENU object at the same time, and there is another difference that an object in the combination is only available at the same time. It belongs to a constituent object, while a part of the polymerization can be aggregated by multiple overall objects, such as a student can read in multiple schools, and a menu can only be an object within a window at the same time. Relationship is relatively simple, refers to a class that describes another contract for another class. For classes, it is a class that implements an interface public interface a {public void methoda ();} public class b importa () {public void methoda () {...} ...} General in the face-to-object system In the case of using the interface as much as possible to reduce the coupling between the class.