in reply to Inherit only few methods from a parent class

It sounds like you're taking the wrong approach. One of the selling points of inheritance is that your child classes behave just like the parent classes (at least interface-wise), and are therefore interchangeable (polymorphism).

If you're looking to simplify the interface to the base class, I wouldn't use inheritance at all. Make a new class as a wrapper around the more complicated class, sort of like the facade design pattern.

Example:

package ComplicatedClass; sub new { my $class = shift; return bless {}, $class; } sub method1 { print "This is method 1\n"; } sub method2 { print "This is method 2\n"; } .. sub method99 { print "This is method 99\n"; } sub method100 { print "This is method 100\n"; } package SimpleClass; sub new { my $class = shift; my $cc = new ComplicatedClass; return bless { cc => $cc }, $class; } sub method1 { my $self = shift; $self->{cc}->method1; } sub method42 { my $self = shift; $self->{cc}->method42; } sub method99 { my $self = shift; $self->{cc}->method99; } package main; my $obj = new SimpleClass; $obj->method1; $obj->method42; $obj->method99; $obj->method2; # Can't locate object method "method2" via package "Sim +pleClass"

Replies are listed 'Best First'.
Re^2: Inherit only few methods from a parent class
by Anonymous Monk on Jul 14, 2009 at 14:10 UTC
    I tried the the approach expalined by lostjimmy. But when ever I instantiate my complicated class,it opens a transaction(in the new()) and half of the methods depends on that transaction, which I is not useful in my simple class.
    Is there any way when I instantiate a complicated/parent class,that the complicated/parent class can detect which simple class is calling them, so that I can add logic to not open the transactions..

      You could simply add a second constructor, in which you can skip opening transactions (e.g. ComplicatedClass::new_no_trans).

      That being said, this design seems like it is going to turn in to a maintenance nightmare.