Article View: comp.lang.eiffel
Article #1277inheritance and generic parameters
From: jos
Date: Mon, 09 Jan 1989 09:24
Date: Mon, 09 Jan 1989 09:24
51 lines
2254 bytes
2254 bytes
> Too bad you didn't have access to the actual system; then you could
> have seen that solution 1.2b is indeed used in the graphical library
> (class GEN_WINDOW). The class actually inherits from
>
> TREE [like Current]
The class variant should include something like w.child = w.child_value.
(GEN_WINDOW is a hierarchical window class.)
This seems like a waste of memory. The value is always kept twice.
Also, it is a kind of redundancy that should be avoided if possible.
In this case you need a class TREE without generic parameter.
This is a general problem, which can occur for each class with generic
parameters. You need the same class with and without generic parameter.
You can make a non-generic class from a generic one, using class invariants
like the one above, but you can make a generic class from a non-generic one
in a conceptually cleaner way. In eiffel the solution could be as follows:
Define a class ITREE without generic parameters. This class should look
exactly like the existing TREE class. Also define a class GEN_VALUE:
class GEN_VALUE[T] export
value, change_value
feature
value : T;
change_value(new : T) is
do
value := new;
end;
end;
Now the generic class TREE can be defined as something like:
class TREE[T] export ... -- same as ITREE and node_value, change_node_value.
inherit ITREE,
GEN_VALUE[T] rename value as node_value,
change_value as change_node_value;
end;
The class GEN_VALUE should be defined only once and can be inherited by
each class that needs a generic version.
In this way it is easy to support the same class with and without generic
parameters. And the redundancy expressed by class variants like
w.child = w.child_value is not needed anymore.
Jos Warmer
jos@cs.vu.nl
...uunet!mcvax!cs.vu.nl!jos
Technical Details
Message-ID:
<1874@vlot.cs.vu.nl>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!jos@cs.vu.nlShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!jos@cs.vu.nl From: jos@cs.vu.nl Newsgroups: comp.lang.eiffel Subject: inheritance and generic parameters Message-ID: <1874@vlot.cs.vu.nl> Date: 9 Jan 89 09:24:05 GMT Sender: jos@cs.vu.nl Reply-To: jos@cs.vu.nl () Organization: VU Informatica, Amsterdam Lines: 51