Gerad Welch > Object-Interface > Object::Interface



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 1.0   Source  


Object::Interface - allows specification of an abstract base class


    package abstract;

    use strict;
    use Object::Interface qw( func1 func2 func3 );


    # Any classes derived from abstract must now contain the functions
    # specified in the 'use' statement, e.g. func1, func2, and func3.


Object::Interface allows class modules to be declared as abstract base classes, or in C++ parlance, pure virtual classes. That is to say, any class derived from a module using Object::Interface must implement the specified routines from that module. Object::Interface differs from C++'s pure virtual functions in that functions may be defined and coded in the abstract base for the derived class to call (via SUPER). This allows common code to be written in the base class. For example:

    package IO::Base;

    use strict;
    use Object::Interface qw( open close read print eof ); # etc.

    sub open
      return open @_;

    # etc.

Object::Interface simply specifies a signature of functions that any derived class must implement, not what the derived class can or cannot do with the methods.

syntax highlighting: