Is it an issue to have multiple almost identical interfaces?
In our company we have 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)
- Less code (not much less, but still)
- If we want to change behavior of our documents, we need to fix 1 interface + 9 realizations instead of 9 interfaces + 9 realizations.
- One interface is more abstract and less tied to business logic (compared to those interfaces for every document type)
The minuses are:
- 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:
- Is it an issue to have multiple almost identical interfaces?
- Which is better to have one unified interface or interfaces for every document type?
- 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?