百度地图聚合示例
Aggregation in Java is a relationship between two classes that is best described as a "has-a" and "whole/part" relationship. It is a more specialized version of the association relationship. The aggregate class contains a reference to another class and is said to have ownership of that class. Each class referenced is considered to be part-of the aggregate class.
Java中的聚合 是两个类之间的关系,最好将其描述为“具有”和“整体/部分”关系。 它是关联关系的更专业版本。 聚合类包含对另一个类的引用,并说拥有该类的所有权。 引用的每一个类被认为是部分的聚合类。
Ownership occurs because there can be no cyclic references in an aggregation relationship. If Class A contains a reference to Class B and Class B contains a reference to Class A then no clear ownership can be determined and the relationship is simply one of association.
发生所有权是因为聚合关系中不能存在循环引用。 如果A类包含对B类的引用,而B类包含对A类的引用,则无法确定明确的所有权,并且该关系只是关联之一。
For example, if you imagine that a Student class that stores information about individual students at a school. Now assume a Subject class that holds the details about a particular subject (e.g., history, geography). If the Student class is defined to contain a Subject object then it can be said that the Student object has-a Subject object. The Subject object also makes up part-of the Student object — after all, there is no student without a subject to study. The Student object, therefore, owns the Subject object.
例如,如果您想象一个学生类存储有关学校中各个学生的信息。 现在假定一个Subject类,其中包含有关特定主题的详细信息(例如,历史,地理)。 如果将Student类定义为包含Subject对象,则可以说Student对象具有 -Subject对象。 Subject对象也弥补了Student对象部分的 -毕竟,有没有受到研究没有学生。 因此,Student对象拥有Subject对象。
例子 ( Examples )
Define an aggregation relationship between Student class and the Subject class as follows:
定义学生类和主题类之间的聚合关系,如下所示:
public class Subject {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName()
{
return name;
}
}
public class Student {
private Subject[] studyAreas = new Subject[10];
//the rest of the Stud
百度地图聚合示例