1. Perl
  2. Module
  3. here

base - inherit class

The base module allows you to inherit classes.

# Class inheritance
package Your Class;

use base 'BaseClass';

Inheritance allows subclasses to call methods in the base class. If a method called parse is defined in the base class BaseClass, you can also call the parse method in the subclass YourClass.

Base class
▲
Subclass ← base class method + own method available

Single inheritance and multiple inheritance

Perl supports multiple inheritance, but multiple inheritance makes the inheritance relationship between modules very complicated. Therefore, it is said that limiting inheritance to single inheritance is good for keeping module relationships simple.

In fact, programming with single inheritance makes the program easy to understand and read. There is nothing you can't do with single inheritance, and the design will be cleaner, so please try to create a program with single inheritance.

FAQ about base module

Q. I have seen a module called parent. How is it different from the base module?

A. The parent module is a simplification of the base module. The roles are the same. parent has become a core module since 5.10.0. The base module is a core module from Perl 5.005. It seems that the base module is often used when inheriting in consideration of portability.

Q. Please tell me the mechanism of inheritance in the base module.

A. In Perl, you can inherit by setting a base class in a package variable called @ISA. The base module only does this at compile time. It has the same meaning as the following implementation.

# Inheritance mechanism
package Your Class;

BEGIN {
  our @ISA = ('BaseClass');
}

Related Informatrion