9.9. A Horse of a Different ColorHaving all horses be brown would be boring. Let's add a method or two to get and set the color: ## in Animal sub color { my $self = shift; $self->{Color}; } sub set_color { my $self = shift; $self->{Color} = shift; } Now you can fix that color for Mr. Ed: my $tv_horse = Horse->named("Mr. Ed"); $tv_horse->set_color("black-and-white"); print $tv_horse->name, " is colored ", $tv_horse->color, "\n"; which results in: Mr. Ed is colored black-and-white Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|