consult relevant textbooks for discussion of Object Oriented definitions and
methodology. This is not intended as a tutorial for object-oriented
programming or as a comprehensive guide to Perl's object oriented features,
-nor should it be construed as a style guide.
+nor should it be construed as a style guide. If you're looking for tutorials,
+be sure to read L<perlboot>, L<perltoot>, and L<perltooc>.
The Perl motto still holds: There's more than one way to do it.
package main;
- $x = Foo->new( 'High' => 42, 'Low' => 11 );
- print "High=$x->{'High'}\n";
- print "Low=$x->{'Low'}\n";
-
- $y = Bar->new( 'Left' => 78, 'Right' => 40 );
- print "Left=$y->[0]\n";
- print "Right=$y->[1]\n";
-
+ $a = Foo->new( 'High' => 42, 'Low' => 11 );
+ print "High=$a->{'High'}\n";
+ print "Low=$a->{'Low'}\n";
+
+ $b = Bar->new( 'Left' => 78, 'Right' => 40 );
+ print "Left=$b->[0]\n";
+ print "Right=$b->[1]\n";
+
=head1 SCALAR INSTANCE VARIABLES
An anonymous scalar can be used when only one instance variable is needed.
package main;
- $x = Foo->new( 42 );
- print "a=$$x\n";
+ $a = Foo->new( 42 );
+ print "a=$$a\n";
=head1 INSTANCE VARIABLE INHERITANCE
package main;
- $x = Foo->new;
- print "buz = ", $x->{'buz'}, "\n";
- print "biz = ", $x->{'biz'}, "\n";
+ $a = Foo->new;
+ print "buz = ", $a->{'buz'}, "\n";
+ print "biz = ", $a->{'biz'}, "\n";
package main;
- $x = Foo->new;
- print "buz = ", $x->{'Bar'}->{'buz'}, "\n";
- print "biz = ", $x->{'biz'}, "\n";
+ $a = Foo->new;
+ print "buz = ", $a->{'Bar'}->{'buz'}, "\n";
+ print "biz = ", $a->{'biz'}, "\n";
$foo->goo;
$foo->google;
+Note that C<SUPER> refers to the superclasses of the current package
+(C<Foo>), not to the superclasses of C<$self>.
+
=head1 USING RELATIONSHIP WITH SDBM
package main;
- $x = FOO->new;
- $x->bar;
+ $a = FOO->new;
+ $a->bar;
Now we try to override the BAZ() method. We would like FOO::bar() to call
GOOP::BAZ(), but this cannot happen because FOO::bar() explicitly calls
package main;
- $x = GOOP->new;
- $x->bar;
+ $a = GOOP->new;
+ $a->bar;
To create reusable code we must modify class FOO, flattening class
FOO::private. The next example shows a reusable class FOO which allows the
package main;
- $x = GOOP->new;
- $x->bar;
+ $a = GOOP->new;
+ $a->bar;
=head1 CLASS CONTEXT AND THE OBJECT
package main;
- $x = Bar->new;
- $y = Foo->new;
- $x->enter;
- $y->enter;
+ $a = Bar->new;
+ $b = Foo->new;
+ $a->enter;
+ $b->enter;
=head1 INHERITING A CONSTRUCTOR
package main;
- $x = BAR->new;
- $x->baz;
+ $a = BAR->new;
+ $a->baz;
=head1 DELEGATION
tie %foo, "Mydbm", "adbm", O_RDWR|O_CREAT, 0640;
$foo{'bar'} = 123;
print "foo-bar = $foo{'bar'}\n";
+
+=head1 SEE ALSO
+
+L<perlboot>, L<perltoot>, L<perltooc>.