Java confusion: extends vs implements
Aug. 20th, 2006 06:42 pmGiven classes A and B,
means that instances of A can invoke methods implemented in 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
I don't yet understand whether this last annoyance is circumvented with "General Multiple Inheritance".
A extends Bmeans that instances of A can invoke methods implemented in B.
A implements Bmeans 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 10:13 pm (UTC)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?