diff options
author | Michael Witten <mfwitten@gmail.com> | 2009-04-07 14:59:29 -0500 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2009-04-07 23:41:32 +0200 |
commit | 64261f91d325cb53a52f189ce3dce7a4ef3c99ec (patch) | |
tree | 851e8287a240f6496dd80c1d1a6333169a5db535 /pod/perlboot.pod | |
parent | 33739d6a0ba1d04240e125eb235b938a92bfb512 (diff) | |
download | perl-64261f91d325cb53a52f189ce3dce7a4ef3c99ec.tar.gz |
Docs: Minor modifications to discussion of constructor
Signed-off-by: Michael Witten <mfwitten@gmail.com>
Diffstat (limited to 'pod/perlboot.pod')
-rw-r--r-- | pod/perlboot.pod | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/pod/perlboot.pod b/pod/perlboot.pod index 242606212e..7d39843a69 100644 --- a/pod/perlboot.pod +++ b/pod/perlboot.pod @@ -561,8 +561,8 @@ Of course, if we constructed all of our horses by hand, we'd most likely make mistakes from time to time. We're also violating one of the properties of object-oriented programming, in that the "inside guts" of a Horse are visible. That's good if you're a veterinarian, -but not if you just like to own horses. So, let's let the Horse class -build a new horse: +but not if you just like to own horses. So, let's have the Horse +class handle the details inside a class method: { package Horse; @ISA = qw(Animal); @@ -578,14 +578,15 @@ build a new horse: } } -Now with the new C<named> method, we can build a horse: +Now with the new C<named> method, we can build a horse as follows: my $horse = Horse->named("Mr. Ed"); Notice we're back to a class method, so the two arguments to C<Horse::named> are C<Horse> and C<Mr. Ed>. The C<bless> operator -not only blesses C<$name>, it also returns the reference to C<$name>, -so that's fine as a return value. And that's how to build a horse. +not only blesses C<$name>, it also returns that reference. + +This C<Horse::named> method is called a "constructor". We've called the constructor C<named> here, so that it quickly denotes the constructor's argument as the name for this particular C<Horse>. |