|
MRP::Interface - defines object interfaces |
MRP::Interface - defines object interfaces
Allows you to specify the interface that an object is expected to implement without implying an inheritance hierachy.
MRP::Interface->create(Foo => {''=>'My realy usefull interface', # interface description
action=>'performs an action', # functions and their descriptions
reaction=>'responds to an action', # ...
});
MRP::Interface->Foo->implementedBy('Bar'); # register package Bar as implementing interface Foo
# Package Bar must have functions 'action' and 'reaction'
# or a fatal error is generated.
$bar = new Bar;
$hoot = new Hoot;
MRP::Interface->Foo->implementedBy($bar); # returns true as $bar does implement Foo MRP::Interface->Foo->implementedBy($hoot); # returns false as $hoot doen't implement Foo MRP::Interface->Gee->implementedBy($bar); # fatal error if interface Gee is not defined
$int = MRP::Interface->Foo; # gets the interface object for 'Foo'
print $int->name(); # prints out 'Foo'
%functions = %{$int->functions()}; # %functions now contains Foo's functions and descriptions
MRP::Interface->create( interfaceName => { '' => $description_for_interfaceName,
func1 => $description_for_func1,
func2 => $description_for_func2,
...
funcn => $description_for_funcn },
otherInterface => { ..... }
);
If the argument is a package name (not a reference) then the package is registered as implementing the interface. If the package does not provide all of the required functions then an error is thrown.
MRP::Interface->Holly->implementedBy($obj) || die "$obj does not implement interface Holly";
Matthew Pocock mrp@sanger.ac.uk
|
MRP::Interface - defines object interfaces |