The parent class is the package Books.pm
The child class is Physics.pm. This child
will inherite from the parent package Books.pm.
#!C:/Perl/bin/perl.exe -w
#1. The main scripts
package Physics;
use Books;
use strict;
our @ISA = qw(Books);
# will inherit from Book package (class)
#2. Override the constructor of the parent class
sub new {
my ($class) = @_;
# Call the constructor (the new() of the Books.pm) of the
# parent class, Books:
my $self = $class->SUPER::new( $_[1], $_[2], $_[3] );
# Add few more attributes
$self->{_title} = undef;
$self->{_author} = undef;
bless $self, $class;
return $self;
}
# Override the helper function "get discipline"
sub get_discipline {
my( $self ) = @_;
return $self->{_discipline};
}
# Override the helper function "set discipline"
sub set_discipline{
my ( $self, $discipline ) = @_;
$self->{_discipline} = $discipline if defined($discipline);
return $self->{_discipline};
}
# Override the helper function "get title"
sub get_title {
my($self ) = @_;
return $self->{_title};
}
# Override helper function "set title"
sub set_title{
my ( $self, $title ) = @_;
$self->{_title} = $title if defined($title);
return $self->{_title};
}
1;
|