Although theoretically reasonable, this ability to have attributes (and/or methods) in a derived class completely different semantically than in the derived class is usually not very practical. As stvn points out, most OO developers aren't bothered by this lack.

I would go a bit further and say that any design based on this kind of feature is highly suspicious.

Contrary to what many people seem to have learned about OO, inheritance is an extremely strong form of coupling. You can't really ignore your base class while deriving. After all, by inheriting you are declaring that the derived class is just like the base class with a few extensions (or specializations). That is after all what an ISA relationship means.

Having a public attribute in a derived class that is radically different from the same named public attribute in the base class is a recipe for maintenance nightmares (he says from personal experience).

I am not (yet) a big user of Moose. But I've been doing OO in multiple languages for about 15 years. I have seen many systems that have tried to take advantage of this kind of feature over the years. Every single one of them was a source of ongoing bugs and pain.

I feel that if you find yourself in this position, the code is trying to tell you that you need to revisit your design.

G. Wade

In reply to Re: attribute collisions ín Moose by gwadej
in thread attribute collisions ín Moose by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.