How about the property that the width and height (of a Rectangle) are independent:
package Rectangle; use Moo; has height => (is => 'rw'); has width => (is => 'rw'); sub demo { my ($self) = @_; printf "Demo of %s\n", ref $self; $self->show_dimensions; printf "Resetting height => 4, width => 3\n"; $self->height(4); $self->width(3); $self->show_dimensions; printf "area: %d\n", $self->area; $self->show_dimensions; } sub area { my ($self) = @_; $self->{width} * $self->{height}; } sub show_dimensions { my ($self) = @_; printf "height: %s, width: %s\n", $self->{height} || 'undef', $sel +f->{width} || ''; } package Square; use Moo; extends 'Rectangle'; sub area { my ($self) = @_; $self->{height} = $self->{width}; $self->SUPER::area(); } package main; my $rect = Rectangle->new(width => 2, height => 2); my $sq = Square->new(width => 2); $rect->demo; print "\n"; $sq->demo;
Which outputs:
Demo of Rectangle height: 2, width: 2 Resetting height => 4, width => 3 height: 4, width: 3 area: 12 height: 4, width: 3 Demo of Square height: undef, width: 2 Resetting height => 4, width => 3 height: 4, width: 3 area: 9 height: 3, width: 3
The square fails as a stand-in for a rectangle. The is one of the reasons that wise man say Favor Composition Over Inheritance

In reply to Re^4: When to Use Object Oriented approach in Perl? (RFC) by Arunbear
in thread When to Use Object Oriented approach in Perl? (RFC) by thanos1983

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.