Reputation: 15347
I have a reasonably large application that has a lot of base classes. I want to change this into interfaces, to allow (easier) unit testing.
However, when I make a new 'design' of the interfaces I might use, I notice that some classes will inherit from 5 or more interfaces. Can this cause problems?
I ask this since I don't want to refactor the whole application to find out it will not work; or if there is a nice solution, to take this into the refactoring steps.
Some of the interfaces I had in mind (pseudo code). It is incomplete but it shows the interface relations I want to make (there will be many more). E.g. IBank derives from 5 interfaces, and I think more will be needed.
INavigation: IOffset
INavigation Root { get; }
INavigation Parent { get; }
IMemory
string FileName { get; set; }
byte[] Content { get; }
Model Model { get; }
IPcgMemory: IMemory
ProgramBanks ProgramBanks { get; }
CombiBanks CombiBanks { get; }
SetLists SetLists { get; }
DrumKitBanks { get; }
WaveSequenceBanks WaveSequenceBanks { get; }
ISelectable
bool IsSelected { get; set; }
ICountable
int Count { get; }
IName
string Name { get; set; }
IOffset
int ByteOffset { get; set; }
IPatch: IName, ISelectable, IOffset, INavigation
IBank: ICountable, IName, ISelectable, IOffset, ICountable, INavigation
IEnumerable<Patch> Patches { get; }
IProgramBank: IBank
ICombiBank: IBank
ISetList: IBank
IWaveSequenceBank: IBank
IDrumKitBank: IBank
IBanks: ICountable, INavigation, ISelectable, IOffset, ICountable
IEnumerable<IBank> Banks { get; }
IProgramBanks : IBanks
int CountModeledPrograms { get; }
int CountSampledPrograms { get; }
ICombiBanks: IBanks
ISetLists: IBanks
IWaveSequenceBanks: IBanks
IDrumKitBanks: IBanks
PcgMemory: IPcgMemory
ProgramBanks: IPatchCollection
Upvotes: 4
Views: 84
Reputation: 156918
I wonder what problems you expect. List<T>
derives from 8 interfaces (IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
) and I have never seen the problem with it.
The problem might be when you are going to test this, having that much relationships between interfaces, it takes a lot of work to create test objects, but that comes with the job I think. Try to find out if you really need all those interfaces, maybe you can combine them or skip them.
Upvotes: 4