preface 
 
  Look_up Engine  
 
  email how to  
 
  counter  
 
  regex  
 
  search engine  
 
  home  
 
  ask us  
 

 

Perl scripting


Applications


OO Perl


Perl & Databases


Search a word:
   



© The scientific sentence. 2010

Perl OOP Inheritence
Perl OOP Inheritence

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;
  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2007. All rights reserved.