我目前在Code中实现三元关联时遇到了一些麻烦.
我得到二进制的,
但我不确定三元协会.
这是大学里的典型情景.
讲师可以向一个或多个学生讲授一个科目
学生只能从一位讲师那里学一门科目
讲师可以教一个学生只有一个科目
这三个类之间存在三元关联.
我已经在互联网上阅读了关于这一点的不同来源,并且找不到解决方案
如何实现这三个类之间的关联?要么,
一般来说,在类之间实现关联的可能方法是什么(在java中)?
解决方法:
一如既往,这取决于.
实现关联类的常用方法是使用关联数组.在您的示例中,您(最终)有一个Lecturer / Subject的组合来访问学生列表.如果您的要求不同,您可以在提供教师时返回主题/学生列表.
使用数据库时,您将在表格教学中获得讲师/主题/学生的主键.这允许个人选择,如上所述.
我的一些伪代码:
class Teaching {
private Hash lectRef; // assoc. array
public void addTeaching(Lecturer lect, Student stud, Subject subj) {
if lectRef[lect.hash] == None { lectRef[lect.hash] = []; }
// if none, default an empty array here
// lect.hash is a unique hash code for the Lecturer object
lectRef[lect.hash].append((stud, subj);
// tuple of student/subject referenced
// if you need other fast results (e.g. subjects per student or the like) you need to hash them here too
}
public [(Stud, Subj)] studSubj (Lecturer lect) {
return lectRef[lect.hash];
// returns the array of student/subject tuples
}
// add other result operations like subjects per student as needed
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。