Hi Monks,

I have my lib structure as follows. I have created every module file to follow Object-oriented concepts (OOPs).

Now I wish to inherit every method by package A, B, C & D as they are needed always to interact with the app.

I have strong feeling that the way I am creating the constructor in C1.pm is definitely not followed by PERL/OOPs.

In the end, I would like to do:- if I create an object for C1 it should (inherit and) give me access to all the methods available A, B, C, D

I am seeking for advice on how this should be achieve in more perlish way taking into OOP's in consideration.

lib/ | ----A.pm #has method new | ----B.pm #has method new | ----C.pm--- #has method new | | | ----C1.pm #has method new | -----D.pm #has method new #############################################
Package C1; use File::FindLib 'lib'; use A; use B; use C; use D; sub new { return bless({ _a => A->new->bar, _b => B->new->bar1, _c => C->new(), _d => D->new(), }, shift); } sub foo { my ($self) = (@_); my $a = $self->{_a}; my $b = $self->{_b}; my $c = $self->{_c}; my $d = $self->{_d}; $a->some_method1(); { .... #set of operations } } sub abc { my ($self) = (@_); my $a = $self->{_a}; my $b = $self->{_b}; my $c = $self->{_c}; my $d = $self->{_d}; $c->some_method2(); { .... #set of operations } }

In reply to object oriented Perl advice / constructor creation in child class by smarthacker67

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.