Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Recovering masked methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-16 (13:25)
From: John Prevost <j.prevost@c...>
Subject: Re: [Caml-list] Recovering masked methods (with CamlP4?)
>>>>> "ab" == Alessandro Baretta <> writes:

    ab> In my code, class a = object method m = ... end Provides basic
    ab> functionality common to all my inheritance hiearchy. Class a
    ab> *also* defines the actual type of all my inheritance
    ab> hieararchy, so I do not use subtyping at all; I use type
    ab> *identity*. That's because I'm building a graph of objects of
    ab> different classes, so all the objects in the graph need to
    ab> have the same type. I only use inheritance because of code
    ab> sharing. Now, class b = object inherit a ... end performs
    ab> extensive personalizations to the functionality provided by
    ab> class a, while always retaining the functionality of the
    ab> parent, which is accessed by sending messages to
    ab> super_a. Class var_b needs most of the functionality provided
    ab> by b, with the sole exception of one method, which I call here
    ab> m, which needs to be identical to the one defined in the root
    ab> of the hierarchy.

Okay--let me rephrase what you just said to make sure I understand

You have a class "a" which has a lot of common methods.

You have a class "b" which reuses and changes those.

You have a class "var_b" which is identical to "b" except that method
"m" is the same as "a".

If that is correct, I have no idea why you want to inherit the way
you've been talking about!  Why in heaven's name wouldn't you just

class a =
    method m = ...
    method m1 = ...
    method m2 = ...

class var_b =
    inherit a
    method m1 = ...
    method m2 = ...

class b =
    inherit b
    method m = ...

You've simply got the wrong ordering in your inheritance.  There's
absolutely no need for more functionality to support accessing "older"
methods in this case.  (I'd argue there's no need in any case.)  And
again, even if method m had to be different in var_b, it would be
better to use an inherited class which has the features common to b
and var_b.  In this case, that class is identical to b.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: