|
![](/i/fill.gif) |
Am 14.08.2012 13:00, schrieb Warp:
> clipka <ano### [at] anonymous org> wrote:
>> Am 13.08.2012 19:26, schrieb Warp:
>
>>>> Yeah, I don't know. I'm slowly coming around to the idea that maybe we
>>>> should forget about all this "inheritance" stuff and focus on interfaces
>>>> as the primary thing of interest...
>>>
>>> How would you implement a GUI library without using any kind of inheritance?
>
>> By using /interfaces/ maybe?
>
> Given that interfaces cannot contain member variables nor function
> implementations (at least not in any language I know of), it would make
> the GUI library *really* annoying to use because of all the required code
> repetition. (For example, every time the library needs to know the
> coordinates of the object on screen, it would have to call a function
> declared in the interface, which the user would have to implement in his
> own code to return those coordinates.
I guess you've heard of code re-use through delegation, no?
> It would also cripple any possibility
> of using eg. a screen element that contains other screen elements, because
> such an object would just be an interface and cannot contain anything.)
I have no idea what you're saying there. If you're saying what I'm
reading, it's plain nonsense.
>> You can argue that a class that implements an interface effectively
>> "inherits" from it, but you can also argue against it. It's a matter of
>> how exactly you define "inheritance".
>
> Inheritance implements the OO concept of an "is-a" relationship. If a class
> implements an interface, then it effectively has an "is-a" relationship to
> it. (For example, if the interface is named, let's say, ButtonListener,
> and you implement it, then your class "is-a" ButtonListener. You can give
> an object of your class to anything that expects a ButtonListener. It doesn't
> get any more straightforward and clear inheritance than that.)
In common parlance, "inheritance" means "multi-level inheritance" though
(and in the OP quoted above it was obviously meant that way), and a
single tier of interfaces and a single tier of implementing classes
doesn't really cut it.
I do agree that at least inheritance among interfaces would be nice to
have, but it's not entirely impossible to implement a GUI library even
without that.
Post a reply to this message
|
![](/i/fill.gif) |