开发者

Describing relationship between objects for use in code

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 int开发者_开发百科erface 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.


Have you considered changing it so that the dependency knows the resource and the hard/soft nature?

public interface IDependency
{
    IResource Resource { get; }
    DependencyType Type { get; }
}

public interface IResource
{
    IEnumerable<IDependency> Dependencies { get; set; }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜