gusl: (Default)
[personal profile] gusl
Given classes A and B,

A extends B
means that instances of A can invoke methods implemented in B.

A implements B
means that A implements the interfaces in B. The methods are implemented in A.

In this sense, "extends" and "implements" are opposites.

But I often think of them as being the same, because with the class names normally used, both of them can be read as "ISA". This is confusing.

I think the solution is to consciously distinguish "is a subtype of" from "is an implementation of".

---

Multiple inheritance is a bit tricky. I don't understand how all these things fit in, but from here I learned that:

* You need to create a new class Child, to be the result of the mix between Parent (first parent) and Other (second parent).
* Child extends Parent and implements 2 interfaces, MProvides and MRequires.
* There is a class called Mixin, used for the purpose of communicating with Other, which implements MProvides, and whose constructor requires an instance of MRequires. This instance simulates a parent-class for Mixin.
* The Child's constructor instantiates a Mixin, passing itself "this" as an argument. For each method func(...) that you inherit from Other, you need to write a implement a method mixin.func(...)

I don't yet understand whether this last annoyance is circumvented with "General Multiple Inheritance".

(no subject)

Date: 2006-08-21 09:46 pm (UTC)
From: [identity profile] ekorber.livejournal.com
Yes, but it's entirely accurate to say "An interface is a totally abstract class, where you use the keyword implements instead of extends, and you can implement more than one of them."

If the compiler was smart enough to tell when a class was totally abstract (which I'm pretty sure is impossible in any practical sense), we wouldn't need interfaces at all. We could just allow multiple extends and require that at most one of the classes extended be a non-totally-abstract-class.

(no subject)

Date: 2006-08-21 10:13 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
If the compiler was smart enough to tell when a class was totally abstract (which I'm pretty sure is impossible in any practical sense)

Can't you tell from the method declarations? i.e. a class without internal curly brackets is totally abstract.

Is there any reason they shouldn't have used "extends" for both superclasses and interfaces?

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags