Michael Fowler wrote:
> 
> On Fri, Sep 01, 2000 at 11:41:47AM -0700, David E. Wheeler wrote:
> > Michael Fowler wrote:
> > >
> > >     my Dog $spot;           # $spot is now a blessed Dog object
> > >     $spot->name("Fido");    # $spot->{'name'} eq "Fido"
> > >
> > >     print ref $spot;        # yes, "Dog"
> > >
> > >     $spot = new Dalmation;  # now $spot is a Dalmation object
> >
> > Yes, but the Dalmation $spot will *not* have the name "Fido," will it?
> 
> Nope, $spot is now an entirely new object.

Well then, that makes this example rather wasteful, doesn't it?

  my Dog $spot;
  if ($input eq 'Collie') {
      $spot = Collie->new;
  } elsif ($input eq 'Dalmation') {
      $spot = Dalmation->new;
  }

Becuase we're creating two objects when we really only want one.

David

Reply via email to