The base class is an operating system class.
Code
Package OS;
Require Exporter;
@ Isa = QW (exporter );
@ Export = QW (temp );
Sub Getdf {}
Sub Temp {
My $ This = Shift ;
Print $ This -> Getdf ();
Print " \ N " ;
}
Sub New {
My $ Class = Shift ;
My $ This = {};
Bless $ This , $ Class ;
Return $ This ;
}
1 ;
The two subclasses are SunOS and hpos.
Code
Package Hpos;
Require Exporter;
Require OS;
@ Isa = QW (exporter OS );
@ Export = QW ();
My % Cmd = (
' DF ' => ' BDF-l ' ,
' PS ' => ' PS-efx '
);
Sub Getdf {
Return $ Cmd { ' DF ' };
}
Sub New {
My $ Class = Shift ;
My $ This = OS -> New ();
Bless $ This , $ Class ;
Return $ This ;
}
Code
Package SunOS;
Require Exporter;
Require OS;
@ Isa = QW (exporter OS );
@ Export = QW ();
My % Cmd = (
' DF ' => ' DF-KL ' ,
' PS ' => ' PS-ef '
);
Sub Getdf {
Return $ Cmd { ' DF ' };
}
Sub New {
My $ Class = Shift ;
My $ This = OS -> New ();
Bless $ This , $ Class ;
Return $ This ;
}
1 ;
Object creation Factory
Package Factory;
Sub Createos {
My $ Self = Shift ;
My $ OS = Shift ;
Return New SunOS If ( $ OS EQ ' Sun ' );
Return New hpos If ( $ OS EQ ' HP ' );
}
Sub Createdb {
}
1 ;
ClientProgram
# ! /Usr/bin/perl
Push ( @ INC , 'Pwd ');
Use SunOS;
Use Hpos;
Use Factory;
$ OS = Factory -> Createos ( ' HP ' );
$ OS -> Temp ();
$ OS = Factory -> Createos ( ' Sun ' );
$ OS -> Temp ();