returned by the &bigbang "constructor" is not a reference to a blessed
object at all. It's just the class's own name. A class name is, for
virtually all intents and purposes, a perfectly acceptable object.
-It has state, behavior, and identify, the three crucial components
+It has state, behavior, and identity, the three crucial components
of an object system. It even manifests inheritance, polymorphism,
and encapsulation. And what more can you ask of an object?
for each and every constructor you ever write is to speak Perl with
such a severe C++ accent that you do a disservice to both languages.
There's no reason to insist that each class have but one constructor,
-or that that constructor be named new(), or that that constructor be
+or that a constructor be named new(), or that a constructor be
used solely as a class method and not an object method.
The next section shows how useful it can be to further distance ourselves
print $obj3->color(); # prints "vermilion"
Each of these objects' colors is now "vermilion", because that's the
-meta-object's value that attribute, and these objects do not have
+meta-object's value for that attribute, and these objects do not have
individual color values set.
Changing the attribute on one object has no effect on other objects
# invoked as class method or object method
sub has_attribute {
my($self, $attr) = @_;
- my $class = ref $self if $self;
+ my $class = ref($self) || $self;
return exists $class->{$attr};
}
forethought and design. Aggregation instead of inheritance is often a
better approach.
-We use the hypothetical our() syntax for package variables. It works
-like C<use vars>, but looks like my(). It should be in this summer's
-major release (5.6) of perl--we hope.
-
You can't use file-scoped lexicals in conjunction with the SelfLoader
or the AutoLoader, because they alter the lexical scope in which the
module's methods wind up getting compiled.