Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: (jeffa) 3Re: My first stab at OO perl...

by v_thunder (Scribe)
on Jul 17, 2002 at 03:57 UTC ( #182317=note: print w/replies, xml ) Need Help??


in reply to (jeffa) 3Re: My first stab at OO perl...
in thread My first stab at OO perl...

I'm reading through perltoot(1), trying to grok perl's way of doing OO, and it actually recommends doing just what Theseus did. From perltoot:

sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{NAME} = undef; $self->{AGE} = undef; $self->{PEERS} = []; bless ($self, $class); return $self; }

So is this only recommended if you plan to allow for inheritance? Or did I miss something?

-Dan

Replies are listed 'Best First'.
Re: Re: (jeffa) 3Re: My first stab at OO perl...
by v_thunder (Scribe) on Jul 17, 2002 at 04:18 UTC

    Here I go replying to myself again... :-)

    Your code *does* allow for inheritance, it just doesn't allow for someone to create a new instance by calling $foo->new() on an already made instance. Right?

    So: I now get it. Though, personally, I'd rather have it die immediately than not work correctly. And, btw, it's rather confusing to have that bit in perltoot(1).

    Thanks for making me think about this! :)

    -Dan

      No... The way my code is, it WILL allow for you to create a new instance by calling $object->new() on an already running instance, if you remove the code that merlyn disapproves of, it won't die, but it will silently work incorrectly. That's my gripe with it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://182317]
help
Chatterbox?
[shmem]: LanX: oh... now I have to figure out if this is good or bad news.
LanX bad day monks ?
[LanX]: hope you find sleep
[shmem]: LanX: which one?
[LanX]: the last
Discipulus yes a very bad day
[shmem]: grandola, vila morena
[shmem]: LanX: ah, that one. You'll get the bug reports also :P
[Discipulus]: upvote me! i'll make pm great again! ;=)
[shmem]: Discipulus reminds me of an irish saying: "I would guess a tomorrow can wait 'til this day is done" :-)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-04-29 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (534 votes). Check out past polls.