S
StevenECBrown
I'm somewhat of a newbie.
This question has come up for me a couple of times, and it came up
again today: I have an interface IProviderFileVersionNumber that has
this method called GetOrderable. The implementation of GetOrderable
is _always_ exactly the same in each class that implements
IProviderFileVersionNumber, and always will be. It doesn't depend on
any particular details of the implementation. In a sense, I'd like to
put the code for GetOrderable in the interface, but of course I
cannot.
I could make the interface a public abstract class, except that I
think I need multiple inheritance. I have another interface
inheriting from IProviderFileVersionNumber called
IProviderFileVersionNumberOrderable (yes, I know these names are
getting annoyingly long), which needs to be fairly general. On the
other hand, I have specific implementations of these called
PerforceVersionNumber and PerforceVersionNumberOrderable. There is
lots of Perforce-specific stuff in PerforceVersionNumber that
PerforceVersionNumberOrderable needs to inherit, but as you can tell
from the names, PerforceVersionNumberOrderable also needs to be an
IProviderFileVersionNumberOrderable.
If I could multiply inherit classes, the answer would be obvious, but
I can't. Is there any way to avoid duplicating the same code for
GetOrderable across 10 different classes?
Thanks!
Steve Brown
This question has come up for me a couple of times, and it came up
again today: I have an interface IProviderFileVersionNumber that has
this method called GetOrderable. The implementation of GetOrderable
is _always_ exactly the same in each class that implements
IProviderFileVersionNumber, and always will be. It doesn't depend on
any particular details of the implementation. In a sense, I'd like to
put the code for GetOrderable in the interface, but of course I
cannot.
I could make the interface a public abstract class, except that I
think I need multiple inheritance. I have another interface
inheriting from IProviderFileVersionNumber called
IProviderFileVersionNumberOrderable (yes, I know these names are
getting annoyingly long), which needs to be fairly general. On the
other hand, I have specific implementations of these called
PerforceVersionNumber and PerforceVersionNumberOrderable. There is
lots of Perforce-specific stuff in PerforceVersionNumber that
PerforceVersionNumberOrderable needs to inherit, but as you can tell
from the names, PerforceVersionNumberOrderable also needs to be an
IProviderFileVersionNumberOrderable.
If I could multiply inherit classes, the answer would be obvious, but
I can't. Is there any way to avoid duplicating the same code for
GetOrderable across 10 different classes?
Thanks!
Steve Brown