Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found