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

From a design point of view, this looks like a task for Module::Pluggable. If all your modules A, B, C, D provide similar interface, you could just iterate over $self->plugins in your methods instead of spelling out special cases for A, B, C, D manually. Untested pseudo-Perl example:

package Synergy; use Module::Pluggable instantiate => 'new'; sub new { my ($class, @opts) = @_; return bless [ $class->plugins(@opts) ], $class; # now your object contains objects of classes A, B, C, D # and whatever else was in Synergy/*.pm near } sub process { my ($self, @args) = @_; return map { $_->process(@args) } @$self; # passes args to all sub-modules }

On the other hand, if your modules all provide different methods with no intersection whatsoever and you just need to have all of them in one class, you could try to use base to inherit all their methods automatically. This way you only need to spell out your parent packages once.

But if you need to call different parent methods from the same method depending on other circumstances... That sounds like a very complex wrapper. Maybe what you are trying to achieve can be achieved in a simpler way?

Replies are listed 'Best First'.
Re^2: object oriented Perl advice / constructor creation in child class
by smarthacker67 (Beadle) on Jul 11, 2018 at 06:48 UTC
    Hi Sir,

    Thanks for your answer All these A,B,C & D modules have method new so will that cause some conflicts?

      Yes, calling multiple inherited SUPER::new() constructors would be a problem (I don't think mro would help, either), which is why I asked you for more details about modules you are trying to put together.