Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Style 3 is Java interfaces. I loved the concept when I first heard about them, but apparently most older books don't focus on them. (Apparently Java, like Perl, has a huge backlog of obsolete information, advice, and books floating around out there.) I guess interfaces made it into SAX via Java.

    Basically, an interface is like a virtual class, except there's no inheritance involved. Interfaces can be used to give you the benefits of multiple inheritance without actually allowing such. For example, to create a thread you can subclass Thread. But what if you have a Terminal object (itself subclassed from a long line of who knows what) that needs to be a thread? You can declare that Terminal implements the Runnable interface, which means for all intents and purposes that you declare Terminal implements a certain set of methods and the compiler can rely on that fact. Parameters to methods can also be identified only by interface, so Java can really do things like:

    foreach my $obj ($camera, $gun, $craps) { $obj->shoot; }

    but only if you declared each object as implementing a shootable interface or something like that.

    I could really go for interfaces in Perl. I mean, you can program like that already, but I'd like to let the compiler know what I'm doing so it can tell me when I $cat->shoot that I messed up. (presumably)

    I'm not (yet) an XML/SAX guy, so I didn't realize SAX did this. Cool. I'm also not a Java guy, so anything I said here is probably wrong. Or common knowledge. Or both. :)

    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
    • Yes, that's very close to the idea. And in fact, there's a growing number of classes that implement the SAX interface while not having SAX as their central focus. They just want to be usable as SAX handlers to build their internal structure.

      The way we did it is however slightly different as you are not forced to implement anything of the interface. In fact, you could provide any object as a SAX handler and it will still work, even if it implements none of the interface (quite simply, nothing will

      --

      -- Robin Berjon [berjon.com]