【发布时间】:2013-03-11 17:09:38
【问题描述】:
我的界面如下所示:
public interface IOpportunity
{
string Name { get; }
string Description { get; }
ILocation Location { get; }
}
public interface ILocation : IHierarchicalEntity
{
int OpptyCount { get; }
}
public interface IHierarchicalEntity
{
string SID { get; }
string Name { get; }
}
但是,我希望 ILocation 对象也实现以下接口之一:
public interface IHierarchicalEntityWithParentNames : IHierarchicalEntity
{
/// <summary>
/// Returns the lowest level that this heirarchy goes (0 for a flat hierarchy, 1 for a two-level etc.)
/// </summary>
int LeafLevel { get; }
/// <summary>
/// Returns the name of the Segment for the given level (0 for a root node, n for leaf node, where n = LeafLevel)
/// </summary>
/// <param name="level"></param>
/// <returns></returns>
string GetNameForLevel(int level);
}
public interface IHierarchicalEntityWithParentIds : IHierarchicalEntity
{
IHierarchicalEntityWithParentIds ParentEntity { get; }
string ParentSID { get; }
}
由于我正在编写的代码的性质,我无法将这些接口组合成一个具有某种GetParent 方法的接口
在使用这些接口的代码中,我有两个类 - 一个使用 ILocation 对象(如果它是 IHierarchicalEntityWithParentNames),另一个使用 IHierarchicalEntityWithParentIds
我将如何布置接口(也许我必须有一些抽象类)以支持这种“一种或另一种”设计?
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。