develooper Front page | perl.perl6.language | Postings from January 2004

Re: OO inheritance in a hacker style

Thread Previous | Thread Next
Joseph Ryan
January 28, 2004 18:49
Re: OO inheritance in a hacker style
Message ID:
Dmitry Dorofeev wrote:

> Hi all.
> Sorry if this idea|question has been discussed or has name which i 
> don't know about.


> I'd like to write
> Class myclass : a {
> forget method area;
> forget method move;
> method put;
> }
> so methods getX, getY, size will be 'inherited'.
> Methods 'area' and 'move' will be not present in myclass at all!
> so $a = new myclass;
> $a.area()
> will return an error. At some level of inheritance methods area() and 
> move() may be reimplemented again if required.

At first, I thought "Hmmm, I'm not sure if this will be useful.
Besides, what would happen in the case of multipile inheri..."
Then, it hit me.  A "forget" (or "block", or something similar)
keyword would be great in clearing up confusion with multiple

For instance, in an example like:

    class A {
        method a_method {}
        method common_method {}
    class B {
        method b_method {}
        method common_method {}
    class C is A,B { # Is that right, or am I too java-ed out?
        method c_method {}

        forget A::common_method;
        # or maybe something like: "block A::common_method"

Class C would now have access to:
    A::a_method, B::b_method, C::c_method, and B::common_method

Of course, roles are another great way to prevent confusion with
multiple inheritance.  A good question would be whether something
like "forget" is useful in addition, or whether everyone should
just use roles. :)

- Joe

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About