这是协会或聚集的情况下? [英] is this a case of association or aggregation?

查看:210
本文介绍了这是协会或聚集的情况下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发现了大约学生一组课程如何注册一个Java的例子:

I have found a Java example about how students register in a set of courses:

学生-----需要------课程

Student-----takes------Courses

和在本例中被定义为协会,但为什么它不能是聚合?对于我所看到的每一个类都可以独立存在。如何区分这两个?

and in the example is defined as Association, but why it cannot be Aggregation? for what I see each class could exist independently. How do differentiate both?

在我处理的一个学生有课程作为属性的数组,当然有其内生也是一个数组的架构上面的例子;所以在这种情况下,是因为联想两者是相关的,和聚集,因为一个被包含在里面其他?

In the above example I am dealing with the schema that a Student has an array of Courses as attribute, and Course has an array of Students within it also; so in that case is association because both of them are related, and aggregation because one is contained inside the other?

推荐答案

这是不是集合,因为课程是不是学生的集合,一个学生是不是课程的集合。这是一个简单许多一对多关联。我也看到了这一点与封装所需的方法和数据,让学生报名参加课程的关联类者登记为蓝本。聚合的一个例子是如何在一个体商店应用存在一辆车。该车拥有可以独立存在可拆卸的部件(轮胎,发动机,底盘等),但它会知道哪些部件在一个特定的汽车仍存在有用的。

This is not aggregation since a course is not a collection of students and a student is not a collection of courses. This is a simple many-to-many association. I have also seen this modeled with an association class "enrolls" which encapsulates the methods and data necessary to allow a student to sign up for a course. An example of aggregation would be how a car exists in a body shop application. The car has removable parts (tires, engine, chassis, etc.) which can exist independently but it would be useful to know which parts still exist on a particular car.

这篇关于这是协会或聚集的情况下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆