在聚合类中实现连接 [英] Implementing Connections within Aggregation classes

查看:78
本文介绍了在聚合类中实现连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下图中,复制类和书籍类显示了一个汇总(书籍具有副本)。所有其他类都是复制类的子类。现在,假设有一个 Member 类,它必须访问 Copy类的 Lending和 Borrow子类。 成员类唯一应该知道的是 accessionNumber。

In the below diagram, the class "Copy" and class "Book" are showing an aggregation (Book has a Copy). All other classes are sub classes of class "Copy". Now, imagine there is a Member class, which has to access the sub classes "Lending" and "Borrow" of class "Copy". The only thing that 'Member' class should know is "accessionNumber".

如果从代码方面考虑,我的 Book 类包含一个 复制

If we think of this in terms of code, my "Book" class contains an array of "Copy".

我怎么知道一本书的编号?

How can I know the accessionNumber of a particular book?

假设我需要在我的数组中的第三本书的 accessionNumber。但是该数组在 Book 类中,并且没有从<$ c $到 Book 类的连接c> Copy 类。

Lets say I need the "accessionNumber" of the 3rd book in my copies array. But the array is in the Book class, and there is no connection to the Book class from the Copy class.

如果我们建立了连接,是复制有书,还是更有意义的是主题有学生(以著名的聚合示例为例) 学生主题)?

If we create a connection back, would that be like "Copy has a Book", or more meaningfully, something like "Subject has Student" (taking the famous aggregation example "Student has a Subject)?

推荐答案


如果我们创建一个连接回来,就像复制有书

If we create a connection back, would that be like "Copy has a Book"

不,不是。简单的依赖性关系(例如,C ++中的引用或非所有者指针)不是具有或您会从更强大的聚合或组合关联中获得拥有关系。这听起来像是您想要的。

No, it wouldn't. A simple dependency relationship (e.g. a reference or non-owning pointer in C++) is not the "has a" or "owns a" relationship you'd get from the stronger associations of aggregation or composition. That sounds like what you want here.

这篇关于在聚合类中实现连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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