in reply to Re^2: Objects and references
in thread Objects and references

This way you don't care if $class is a reference or not!

And you don't allow people to subclass your class.

Plus, if you're going to do that, do it right:

sub new { return bless {}, __PACKAGE__; }

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^4: Objects and references
by jeanluca (Deacon) on Sep 30, 2005 at 20:40 UTC
    Thanks for your comments!!!!
    Can you also give an example (or link) that demontrates the usage of subclasses.

    Luca
      package Foo; sub new { my $class = shift; return bless {}, $class; } package Foo::Bar; use base 'Foo'; package main; use Foo::Bar; my $foobar = Foo::Bar->new;
      Because there isn't a new() method in the Foo::Bar class, it will use the new() method in its parent class, which is Foo. Because Foo's new() method uses the $class that was passed into new() (which is Foo::Bar), it will DWIM.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?