造型带类的父子关系

编程入门 行业动态 更新时间:2024-10-26 22:22:19
本文介绍了造型带类的父子关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作的一个轻量级的文件管理系统和正在寻找一些帮助,如何最好地某些关系进行建模。从本质上讲,我与两个组织单位的工作:组和键入秒。当一群和类型相结合便形成了链接与文件是那么相关。请注意,组可与多个类型的结合,因此,例如,你可以有一个由链接的'第1组和A类和第二链接组成的1组和B类。在我看来,这是不是真的有结构性的最佳途径,但在这一点上我无法改变它,所以我必须凑合着用,我给什么。

I am working on a lightweight document management system and am looking for some help with how best to model certain relationships. Essentially, I am working with two "organizational units": Groups and Types. When a group and a type are combined they form a Link with which Documents are then associated. Note that a Group can be combined with more than one type, so for example you can have one Link composed of 'Group 1' and 'Type A' and a second Link composed of 'Group 1' and 'Type B'. In my opinion this is not really the best way to have structured it but at this point I'm unable to alter it so I have to make do with what I'm given.

A 文件可以是多个链接 s的成员。因此,例如,文档A'可以是'链接10和链接13'的成员。

A Document can be a member of multiple Links. So for example, 'Document A' can be a member of 'Link 10' and 'Link 13'.

我的问题是,有时我会想显示单文件键,列表中的每个链接的文件所属,和有时我会想显示一个链接并列出每个文件属于该链接。

My issue is that sometimes I will want to display a single Document and list every Link that Document belongs to, and other times I will want to display a single Link and list every Document that belongs to that Link.

我不知道如何表达这些类之间的关系。我看着Composite模式,但我不认为这会为我工作,因为它似乎需要一个孩子只有一个父母,在我的情况,其中一个孩子可以有多个父母。任何帮助,将不胜感激。

I'm not sure how to represent the relationship between these classes. I've looked into the Composite Pattern but I don't think this will work for me because it seems to require that a child have only one parent, where in my case a child can have multiple parents. Any help would be appreciated.

推荐答案

什么你可能寻找是N对M映射。是所有OOP-Y,您可以存储每类中的这些映射:

What you're probably looking for is an n-to-m mapping. To be all OOP-y, you can store these mappings within each class:

// actually write it using properties, information hiding etc instead... public class Document { public ICollection<Link> Links; } public class Link { public ICollection<Document> Documents; // this can be on Document as well, depending on what semantics you want... public void Add(Document d) { Documents.Add(d); d.Links.Add(this); }

更多推荐

造型带类的父子关系

本文发布于:2023-10-25 00:15:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:父子   造型   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!