Since nobody else has mentioned them - there are a couple of similar modules already on CPAN.
Interfaces, Interfaces in Perl? and Re: Interfaces seem to cover similar themes too.
I always saw Java interfaces as a response to the naming resolution problems of C++'s implementation of multiple inheritance. Personally, I think they threw out the baby with the bathwater by only allowing multiple-inheritance of interface :-)
Compile time warnings are a good thing obviously, but that's a separate issue from interface vs. abstract base classes.
I have to admit, I still don't have a handle on how what you want is different from Java-ish interfaces, or inheriting from an abstract class. Can you give an example that shows where abstract classes / interfaces wouldn't be enough?
(If it is different from the Java concept I strongly agree with fever that it should be called something else to avoid confusion :-)
You said:
- I'd like to be able to check that an object I receive from somewhere can handle the operations I'm about to perform on it
- I'd like that check not to dictate the object's implementation of those operations
Inheriting from an abstract base class seems to meet both of these goals - or am I missing something?
There could be an argument for having something like this as a way to retrofit an "abstract" interface onto a pre-existing class. I could see that being useful when you don't control the source.
But if you do control the source expressing the interface using an abstract class (maybe using Attribute::Abstract, Class::Virtual or Class::Virtually::Abstract) would seem more straightforward.
In reply to Re: Class::Interface -- isa() Considered Harmful
by adrianh
in thread Class::Interface -- isa() Considered Harmful
by chromatic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |