Re: Interfaces, Big Deal!!
Hi Franco,
I'm entirely in agreement with you on this issue. Yes, Interfaces have
their (many) uses. But so does multiple inheritance.
My case in point - I create many objects with a totally different nature.
But I want them all to be capable of being in a linked list. I don't want to
have to create a separate class to manage these links. I don't want a
collection or an ArrayList. I simply want a Next and a Prev and a couple of
other trivial bits.
I'd like to define a small linked-list Capability class which I bolt-on to
my other classes through multiple inheritance.
But I can't. :-((
My only recourse is to define an interface, CapLinkable, and <copy> the
code (it's perfectly generic - needs not even a single character to be
changed) into <every> class that is to have this Capability. [I only have this
in C# because I can do it in about 15 lines - in VB it would probably be about
75!!]
But it's a maintenance nightmare, for I cannot even do it with <include>
files - it has to be a textual copy each time!!
There are many small pieces of functionality that would work for many,
many disparate objects without code change required - or in your case, minimal
changes.
Another example is the ability to Serialise. This could be done through
the inheritance of Capabilities. But no, it has to be done by setting an
Attribute and having the serialization done behind the scenes as a fiddle by
the Attribute in conjunction with a Formatter. Why can't an object serialise
<itself> by inheriting from a CapSerializable Capability?
It would be very useful if there were a mechanism for bolting these
Capabilities onto a class without having to reimplement the wheel each time.
Regards,
Fergus
Hi Franco,
I'm entirely in agreement with you on this issue. Yes, Interfaces have
their (many) uses. But so does multiple inheritance.
My case in point - I create many objects with a totally different nature.
But I want them all to be capable of being in a linked list. I don't want to
have to create a separate class to manage these links. I don't want a
collection or an ArrayList. I simply want a Next and a Prev and a couple of
other trivial bits.
I'd like to define a small linked-list Capability class which I bolt-on to
my other classes through multiple inheritance.
But I can't. :-((
My only recourse is to define an interface, CapLinkable, and <copy> the
code (it's perfectly generic - needs not even a single character to be
changed) into <every> class that is to have this Capability. [I only have this
in C# because I can do it in about 15 lines - in VB it would probably be about
75!!]
But it's a maintenance nightmare, for I cannot even do it with <include>
files - it has to be a textual copy each time!!
There are many small pieces of functionality that would work for many,
many disparate objects without code change required - or in your case, minimal
changes.
Another example is the ability to Serialise. This could be done through
the inheritance of Capabilities. But no, it has to be done by setting an
Attribute and having the serialization done behind the scenes as a fiddle by
the Attribute in conjunction with a Formatter. Why can't an object serialise
<itself> by inheriting from a CapSerializable Capability?
It would be very useful if there were a mechanism for bolting these
Capabilities onto a class without having to reimplement the wheel each time.
Regards,
Fergus
Comment