Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I didn't quite rule out AbstractBird, but I did put what is in hindsight a silly restriction on it. So my module is pretty close to what you would want.

As I mentioned in the documentation, an abstract class that inherits from an abstract class will bypass the checks that abstract classes get. Why? Because when it uses the classes further up, they do not trigger their own check, and when someone calls it, it blocks its own check and does not rethrow to the classes that would have implemented the check.

However I required abstract classes to implement at least one abstract method because I didn't think it was worthwhile to not do so. But you have given a good reason. I am about to update the name to AbstractClass. When I have done that your example would look like this. First your abstract base class:

package SwimmingFlyingThing; use AbstractClass qw(swim fly);
Now your abstract class that inherits:
pacakage AbstractBird; use SwimmingFlyingThing; use AbstractClass; @ISA = 'SimmingFlyingThing'; sub fly { print "Flap Flap Flap" }
And then finally a real class:
package Duck; @ISA = 'AbstractBird'; sub swim { print "Paddle paddle paddle" } sub new { ... }
And yes, Class::Contract does indeed implement a similar idea, but is a far bigger change to Perl's inheritance mechanisms.

I am toying with the idea of making abstract classes unable to bless. With my module it would be trivial to do so. Just override bless in derived modules. This time I will be the one to write to Damian to get his opinion... :-)


In reply to Re (tilly) 2: AbstractBase by tilly
in thread AbstractClass by tilly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-28 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found