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

OO inheritance in a hacker style

Thread Next
From:
Dmitry Dorofeev
Date:
January 28, 2004 17:09
Subject:
OO inheritance in a hacker style
Message ID:
20040128121834.63350.qmail@onion.perl.org
Hi all.
Sorry if this idea|question has been discussed or has name which i don't know about.

I am not very good at OO but I tried at least 2 times to develop with it though :-)
Last time it was Java. The problem is that when i going to use some 'standard' class
or 3d party class i'd rather to cut off all unnecessary methods (and may be even properies!),
then adding my own. I know it kills inheritance but it is much more to my Perl habit of hacking code.

example:

Class a {
method getX;
method getY;
method size;
method area;
method move;
}

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.

I see few benefits
1. Much more flexible to build what programmers need. Becouse we have both 'joining' and 'breaking' around us in real life.
2. Inheritance diagrams may become less in size, showing only what programmer use or need in classes.
3. probably there are some optimization possibilities (especially for properties)

i see some drawbacks
1. kills traditional OO mainstream, theory and books
2. hard to keep track both for 'added' methods and for 'killed' methods in mind.
3. hard to know if 'killed' method called from the other methods in the class. But that may be
	not a problem if we just declare forget blah, without affecting run-time.

I am very interested what Perl gurus think about it. Even if you consider this as stupidiest idea ever.
Which is probably true :-)

-Dmitry Dorofeev.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About