c# – Is it an issue to have multiple almost identical interfaces?


Is it an issue to have multiple almost identical interfaces?

In our company we 9 identical interfaces for 9 document types, like: Book, Contract, Person, etc.

interface IBookInner    { Book     GetInnerObject();}
interface IContractInner{ Contract GetInnerObject();}
interface IPersonInner  { Person   GetInnerObject();}

class Book    :IBookInner{...}
class Contract:IContractInner{...}
class Person  :IPersonInner {...}

They all have same method but returing type differs.
And each document type realizes its own interface
(soon I will add one more).

I’ve suggested to replace all of them with one like:

interface IInner {Object GetInnerObject();}

But colleagues answered, that it’s bad idea, because with one interface we need to use dynamic cast (which can cause exceptions), while with separated interfaces we have more stable code.

Is it an issue to have an unique interface for every document type?

I see these pluses of having one interface instead many (almost identical)

  1. Less code (not much less, but still)
  2. If we want to change behavior of our documents, we need to fix 1 interface + 9 realizations instead of 9 interfaces + 9 realizations.
  3. One interface is more abstract and less tied to business logic (compared to those interfaces for every document type)

The minuses are:

  1. With one interface we need to use dynamic cast which can potentially cause runtime exceptions

(Also I should say, that in our company we are trying to use SOLID in our code. I’m not very experienced with SOLID, but I have a feeling that having such interfaces for every type is against dependency inversion principle.)

So my questions are:

  1. Is it an issue to have multiple almost identical interfaces?
  2. Which is better to have one unified interface or interfaces for every document type?
  3. If we look from SOLID perspective, is it good or bad choice to have multiple almost identical interfaces (to avoid dynamic cast) instead of one?