Inheritance

The bless function gives more information to a reference. It makes the reference be of a type: Student in this case. This has several uses in Perl, as we shall see. Using public methods to access private data is not the only benefit of the object-oriented approach. Another important principle, inheritance, is the cornerstone of object orientation.

Inheritance is one of the principal ways of implementing code reuse. The following are examples of inheritance relationships.

  • A Directory is a type of File.

  • A Manager is a type of Employee.

  • A Car is a type of MovingVehicle.

  • A Circle is a type of Shape.

Sometimes inheritance is characterized as the is-a relationship. In the File–Directory relationship, we say that a Directory is-a File. Likewise, ...

Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.