in reply to evolving an OO solution for a bitstream

use BitStream; ... ... my $stream = BitStream::new("bigbinfile"); ... my $bitstr = BitStream::get_bits(128);

I don't see any OO here. You're not even calling class methods. It's just plain sub calling.

Abigail

Replies are listed 'Best First'.
Re: Re: evolving an OO solution for a bitstream
by spurperl (Priest) on Oct 21, 2003 at 11:06 UTC
    Sorry, I pasted incorrect code. It should be -
    use BitStream; ... ... my $stream = BitStream::new("bigbinfile"); ... my $bitstr = $stream->get_bits(128);
    What is OO for you ? Is OO all-of-the-features together, or can we refer to some OO features as OO. Is OO only what uses polymorphism ? I don't think so. True, poly- is one of the most interesting features of OO, but there can be OO without it as well.

    Why I think my code is OO ?

    I have the notion of a BitStream object, which has some internal state and provides some services. This internal state is conveniently encapsulated from the user. The user has no idea how it is implemented, and BitStream's implementation can change at any moment preserving the interface. I can have several BitStream objects, they're separate from each other. etc.

      I can have several BitStream objects.
      Oh, sure, and I guess you use a global variable from which object the 128 bits should be taken if you do:
      my $bitstr = BitStream::get_bits(128);

      You might have objects, but your code snippet doesn't suggest you have them.

      This internal state is conveniently encapsulated from the user. The user has no idea how it is implemented, and BitStream's implementation can change at any moment preserving the interface.
      The internal state of a hash is also conveniently encapsulated from the user. That doesn't make that hashes are objects. Users have no idea how hashes are implemented, and the implementation of hashes can change at any moment, preserving the interface (and in fact, they did between 5.8.0 and 5.8.1). That still doesn't make hashes objects.

      Abigail

        But, if hashes could perform actions (ala %hash->keys vs. keys %hash), you would consider them objects, right?

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.