Perl: Important statements for perl inheritance

From the earlier post you might have learned how to create module files in perl and how does one package inherits from another.

Here is a list of important points to remember.

1) use <parent package name>

2) our @ISA = qw (parent package name)

3) If you are overriding any existing method from parent class then you first need to declare that method with same name and use keyword SUPER. SUPER tells the perl interpreter to locate the method from parent class.

syntax for using SUPER is :

$self = $class ->SUPER::<name of method>(arguments in original method)

Note: If the method from parent class is having 2 arguments then you have to include 2 arguments and not more or less than that. You can add more arguments or assign any value to argument, in the child class.

This is called method overriding in perl.

4) In main executable file you should use only child package, which will inherit all the methods from parent package or packages.

Advertisements

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: