描述代码中使用的对象之间的关系
我需要一种描述两个对象之间关系的方法,但不确定我有什么选择。
我有一个 IEnumerable
并且每个 IResource
都有一个 IEnumerable
依赖项属性。
public interface IResource
{
IEnumerable<IResource> DependentResources{get;set;}
}
每个资源可以有零个或多个依赖资源,并且资源与其依赖资源之间的关系可以是硬关系,也可以是软关系。
我有点不确定在哪里存储有关这种硬/软关系的信息。将关系类型存储在资源中似乎不合适。
一些可能有用的进一步信息:
我最初从所有可能资源的 IEnumerable
开始。该集合中的项目不知道它们与其他资源的关系。
当用户请求给定资源的依赖资源时,将进行 Web 服务调用,带回 Guid 集合。从这个 guid 列表中,我返回有问题的资源及其从原始 AllResources 集合加载的依赖项。
我可以在资源上拥有一个属性,例如:
DependencyTypeEnum.DependencyType ContextualRelationship{get;set;}
或者甚至将硬/软依赖项存储在单独的集合中,但我想知道是否有更好的方法。
I need a way of describing the relationship between two objects and am unsure what options I have.
I have an IEnumerable<IResource>
and each IResource
has an IEnumerable<IResource>
property of dependents.
public interface IResource
{
IEnumerable<IResource> DependentResources{get;set;}
}
Each resource can have zero or more dependent resources and the relationship between a resource and its dependents can either be hard or soft.
I'm a little unsure of where to store the information about this hard/soft relationship. Storing the relationship type in the resource seems out of place.
Some further information that may be useful:
I start initially with an IEnumerable<IResource>
of all possible resources. The items in this collection have no knowlege of their relationships to other resources.
When the user asks for the dependent resources of a given resource, a web service call is made bringing back a collection of Guids. From this guid list, I return the resource in question with its dependents loaded from the origional AllResources collection.
I could have a property on the resource such as:
DependencyTypeEnum.DependencyType ContextualRelationship{get;set;}
or even store the hard/soft dependencies in seperate collections but I'm wondering if there's a better approach to this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过更改它以便依赖项了解资源和硬/软性质?
Have you considered changing it so that the dependency knows the resource and the hard/soft nature?