1
Answer

Interface chaining (?) - Is it acceptable.

csharp

csharp

19y
2.5k
1
I cannot find any information on this - perhaps because it has a name/term I am not aware of.

Basically I have the following structure:

IBaseClassInterface (methods A, B)
IInheritedClassInterface (methods C)

BaseClass <implements> IBaseClassInterface (and the methods A and B)
InheritedClass <inherits> BaseClass <implements> IInheritedClassInterface (and method C)


now if I use the IInheritedClassInterface I cannot access methods A and B.

However: I found that I can make IInheritedClassInterface "inherit" IBaseClassInterface, and can then access the base methods A and B.

I call it interface chaining, but is it a good design practice?  If not why?

Cheers,

Andrew
Answers (1)
0
Brian Manlove

Brian Manlove

NA 6 0 19y
Not a good idea IMHO. Typically I would use an interface to specifically define common methods that would be used by multiple implementors... for example, the classic "Save", "Delete", and "Update" methods of my business objects. I would define the interface with those methods and/or possible overrides of them, and my "customer", "vendor", "order" objects would each implement this common interface. I would instantiate an interface object and then access each implementation object thru this single interface. If I found myself needing to create an object that "chained" interfaces, it would signify to me that my original interface needs some more methods added to it. However, since I'm just someone deep in the trenches and I don't have a lot of time for theoretical pursuits, I'm sure a lot of folks may differ with this opinion.