Paul Johnson wrote:
On Thu, Aug 03, 2017 at 08:44:45PM +0200, hw 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?

You may well find that using roles would provide a better solution than
using inheritance.  The methods would wish to call from both classes
could be defined in one or more roles.  Roles are more usually called
traits in other languages.  You can use roles within Moose or Moo, or by
using other CPAN modules.  You can read more about roles/traits at

  https://en.wikipedia.org/wiki/Trait_(computer_programming)


Hmm.  I think I almost half-way understand what this is about.  For this
case, it seems as if I would have FOO and BAR use traits instead of having
FOO use BAR, and it would be somehow different from using a metaclass FOO
and BAR descend from, like upside-down inheritance turned upside-down again
to finally get it right.

I´m not using Moose or anything yet, though.  I thought it might be better
to start with something basic and perhaps later upgrade.

Why do I have to run into such a problem?  I´m just starting to learn this.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to