У меня есть интерфейс, который выглядит следующим образом:должен реализовать ЯВНО интерфейс A или интерфейс B (ровно один)
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
Как я могу выложить интерфейсы (возможно, мне нужно иметь некоторые абстрактные классы) для поддержки имея этот «один или другой» дизайн?
Я отредактировал ваше название. Пожалуйста, смотрите: «Если вопросы включают« теги »в их названиях?] (Http://meta.stackexchange.com/questions/19190/), где консенсус« нет, они не должны ». –