There is nothing wrong with having an interface which inherits another interface without adding new members, if all implementations of the latter interface will be expected to be able to usefully do things which some implementations of the former may not. Indeed, it's a good pattern which IMHO should have been used more in things like the .net Framework, especially since an implementer whose class would naturally satisfy the constraints implied by the more-derived interface can indicate that simply by implementing the more-derived interface, without having to change any of the member-implementation code or declarations.
For example, suppose I have the interfaces:
interface IMaybeMutableFoo {
Bar Thing {get;set;} // And other properties as well
bool IsMutable;
IImmutableFoo AsImmutable();
}
interface IImmutableFoo : IMaybeMutableFoo {};
An implementation of IImmutableFoo.AsImmutable()
would be expected to return itself; an mutable class implementing IMaybeMutableFoo.AsImmutable()
would be expected to return a new deeply-immutable object containing a snapshot of the data. A routine which wants to store a snapshot of the data held in an IMaybeMutableFoo
could offer overloads:
public void StoreData(IImmutableFoo ThingToStore)
{
// Storing the reference will suffice, since ThingToStore is known to be immutable
}
public void StoreData(IMaybeMutableFoo ThingToStore)
{
StoreData(ThingToStore.AsImmutable()); // Call the more-specific overload
}
In cases where the compiler doesn't know that the thing to be stored is an IImmutableFoo
, it will call AsImmutable()
. The function should return quickly if the item is already immutable, but a function call through an interface does still take time. If the compiler knows that the item is already an IImmutableFoo
, it can skip the needless function call.
IAnimal
andIDog
are terrible tautology names!MyProject.Data.IAnimal
andMyProject.Data.Animal
are better thanMyProject.Data.Interfaces.Animal
andMyProject.Data.Implementations.Animal
Interface
orImplementation
, whether in a repetitive prefix or a namespace either, it is a tautology either way and violates DRY.Dog
is all you should care about.PitBull extends Dog
doesn't need implementation redundancy either, the wordextends
tells me all I need to know, read the link I posted in my original comment.