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
}
}
-
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.