Phoenix.pm: Reminder: Meeting 10/17/2002
Scott Walters
scott at illogics.org
Fri Oct 18 03:39:32 CDT 2002
Everyone,
I forgot what Heather said too, but she made no small point of reminding me when
I got home: under any circumstances, she only wanted *one* book. I still can't
forgive her for winning 4.
Never the less, as promised, my current personal stash - or most of it -
is up on http://wiki.slowass.net/?BookShelf. Feel free to browse the list
and add your own books if you so desire. These are books I'm willing to loan
out - under certain circumstances. See the page for details. If the page
grows too much, I'll try to organize it by subject, dewey decimal, whatever.
Andrew,
Most excellent. Thank you.
Re: factory methods, something like (this is a really dumb example):
package Car::Factory;
sub create_car {
my $self = shift;
my $passengers = shift;
my $topspeed = shift;
return new Car::Ford if $topspeed < 100 and $passengers >= 4;
return new Car::Honda if $topspeed < 120 and $passengers <= 2;
return new Car::Porsche if $topspeed > 160 and $passengers <= 2;
# etc
}
To be OO "pure" (polymorphic) each kind of car should @ISA = (Car), so that
they pass the $ob->isa('Car') test. This lets programs know that it is a car
(reguardless of kind) and can thus be used interchangably.
If you just want to cheat and bless something into a package:
sub create_car {
# this way we can do Car::Factory->create_car(...) or $carfactoryref->create_car(...)
my $package = shift; $package = ref $package if ref $package;
my $car = new Car::GenericAmericanCar;
my $kind = shift;
return bless $car, 'Car::Ford' if $kind eq 'ford';
return bless $car, 'Car::Dodge' if $kind eq 'dodge';
return bless $car, 'Car::Buick' if $kind eq 'buick';
return bless $car, 'Car::Pontiac' if $kind eq 'pontiac';
die "I don't think we make $kind in this country. Try Mexico.";
}
If you do something like that, you will prolly want Car::Ford to inherit
Car::GenericAmericanCar with a line at the top reading
@ISA = qw(Car::GenericAmericanCar Car)
so that the methods continue to be available after you re-bless it (and so that
they are marked as being a Car).
-scott
More information about the Phoenix-pm
mailing list