Andrew Solomon wrote:
My instinct before trying this would be to move the methods which FOO needs
back into FOO (removing them from BAR).
Is there a reason this won't work for you?
Hmm. I haven´t thought of that because they don´t belong into FOO.
They also won´t work in FOO because both FOO and BAR know about the object
they represent via what you could call a handle. This handle is very much
like an index of a row in a table in a database. The handle BAR knows can
be used with objects represented by BAR, and the handle FOO knows can be
used with objects represented by FOO. Though these handles are identical,
their content differs. You can do things with BAR-objects you can´t
do with FOO-objects and vice versa. FOO and BAR are partly the same,
partly different, that´s why there´s a class for each of them and why
BAR is descended from FOO.
If I moved the methods from BAR into FOO, they would use the handle of FOO
instead of the handle of BAR. All the methods in FOO would need a way to
somehow figure out whether they can be used in the current context (i. e.
what type of object the class has been instantiated for) or not.
I could add an object type so that the instances can know what type of
object they represent, and BAR would then become obsolete because I could as
well move all methods from BAR into FOO, defeating the point of OOP.
On Thu, Aug 3, 2017 at 7:44 PM, hw <h...@gc-24.de <mailto:h...@gc-24.de>> wrote:
Hi,
suppose I have a class FOO and a class BAR. The parent of BAR is FOO.
I would like FOO to /use/ BAR because BAR has some methods needed by FOO.
BAR is /decended/ from FOO because FOO has many methods needed by BAR.
Is this possible, or does it lead to some endless recursion when compiling?
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
<mailto:beginners-unsubscr...@perl.org>
For additional commands, e-mail: beginners-h...@perl.org
<mailto:beginners-h...@perl.org>
http://learn.perl.org/
--
Andrew Solomon
Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/