haggs has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interfaces
by ivey (Beadle) on Jun 06, 2000 at 23:54 UTC | |
and then override the methods in the subclasses:
that's very basic code...would it do something like what you want? | [reply] [d/l] [select] |
by btrott (Parson) on Jun 07, 2000 at 03:16 UTC | |
| [reply] [d/l] |
by merlyn (Sage) on Jun 07, 2000 at 04:17 UTC | |
I'd simplify the whole lot of that by doing what use subs does directly: No fuss, no muss, and you even get a distinguishing mark. | [reply] [d/l] [select] |
by ivey (Beadle) on Jun 13, 2000 at 22:44 UTC | |
by chromatic (Archbishop) on Jun 07, 2000 at 03:01 UTC | |
That way, you know exactly which subclass isn't overriding it. | [reply] [d/l] |
|
Re: Interfaces
by Dominus (Parson) on Dec 01, 2000 at 04:28 UTC | |
Well, I have an idea, but I've never really tried it out, so I don't know how practical it is. My idea is that the abstract base class can keep track of who is derived from it, and have an INIT block that checks to make sure all its derived classes define the appropriate methods. The INIT block is called after compilation is complete, but before program execution begins. A test implementation looked reasonable:
Abstract wants its subclasses to define swim and fly methods. If you define a class, say Fish, which inherits from Abstract and defines a swim method but no fly method, you get a fatal error at compile time: Here's the Fish I used: Then test with perl -e 'use Fish'. There are some problems with this implementation. For example, you might want some way to derive less-abstract classes from the abstract base class, and this implementation doesn't allow that. But I think the basic idea is sound. The other thing that came to mind is that Damian Conway probably has something interesting to say about this. Have you checked his book?
| [reply] [d/l] [select] |
by petemar1 (Pilgrim) on Apr 30, 2005 at 00:20 UTC | |
Given...
...What's a clean way of doing that using Class::Contract ? | [reply] [d/l] [select] |