| Next | February 2001 | Slide #25 |
$person = Person->new();
$person = Person->new('Name');
$person = Person->new('Name', 23); # specify name and age
$person->name('Name'); # set name
$name = $person->name; # get name
$person->age(23); # set age
$age = $person->age; # get age
# This should also set $person2's spouse to $person1
$person1->spouse($person2); # set spouse
$spouse = $person1->spouse; # get spouse
$spouse_name = $spouse->name; # get spouse's name
# This should return a string of the form:
# "Person Claudius is 23 years old
# or
# "Person Claudius is 23 years old and is married to Gertrude
$person->as_string
Use the person-test.pl program that I supplied to test the class.
$person = Person->new(...);
should continue to work as before, and
$person2 = $person->new;
should also work. If called as an object method, the constructor should return a copy of the object on whose behalf it is called.
| Next | ![]() |
Copyright © 2001 M-J. Dominus |