Inheritance of Interfaces ("like in Java") 
Author Message
 Inheritance of Interfaces ("like in Java")

> I am VERY unexperienced with Eiffel, but one thing that I miss is the
> multiple inheritence that Java provides with interfaces (and C++ in
> other ways).  Is there any way to do something equivalent in Eiffel?

Yes - simply write each interface as an abstract Eiffel class using the
deferred keyword.

Inherit from these abstract interface classes into your descendant class.

Here's an example, in Java:

   interface Movable {
      abstract public void move(int x, int y);

   class Sprite implements Movable {
      public void move(int x, int y) { ... }

..and in Eiffel:

   deferred class Movable
      feature move(x, y: INTEGER) is deferred end

   class Sprite inherit Movable
      feature move(x, y: INTEGER) is do ... end

You can specify much more than just the interface in a deferred Eiffel
class (for example: partially-implemented algorithms, or contract
specifications) but you can discover these beauties of Eiffel later,
after you've used it for a while in the Java style to which you are

>  Is
> ther a good reason why there shouldn't be? (Or did it just happen that
> way?)

The Eiffel compiler is smart enough to know that deferred classes specify
interfaces, so it uses the same reserved word "inherit" that is used for
regular inheritance. If this bothers you, just add "_INTERFACE" to the
names of your deferred classes.


PS: On the subject of Multiple Inheritance, I found this interesting
analysis in an article by Bryan Boreham (SIGS Application Development
Advisor Sep-Oct 1997 page 36). It's discussing the history of C++:

> There were several other languages such as Eiffel, Objective C and
> Smalltalk being sold heavily as competitors for OO development, and
> any significant feature that would set them apart from C++ was
> trumpeted loudly. Multiple Inheritance was announced as a new feature
> in the second version of Cfront long before the product was released
> but early enough to diffuse the threat from Eiffel.

-- Roger Browne, 6 Bambers Walk, Wesham, PR4 3DG, UK | Ph 01772-687525
-- Everything Eiffel: http://www.*-*-*.com/ | +44-1772-687525

Mon, 08 May 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. using "INVOKE" to mimic Java Interfaces

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. "Array inheritance"

4. help, ferepeated inheritance "problem"

5. Looking for "Restricted Multiple Inheritance" paper

6. Followup to "Itk option inheritance woes"

7. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

8. The Next "Java?"

9. "Smalltalk-Java Contract-Virginia"

10. "Microsoft brewing Java-like language"

11. "Smalltalk-Java Contract-Virginia"

12. "Smalltalk-Java Contract-Virginia"


Powered by phpBB® Forum Software