in reply to OO: Factory vs. "Seed" (?) pattern

What does this line do?

my $factory = AnimalFoodFactory->new;

You don't seem to be using $factory afterwards.

Replies are listed 'Best First'.
Re^2: OO: Factory vs. "Seed" (?) pattern
by water (Deacon) on May 14, 2005 at 10:33 UTC
    Good catch. I meant this
    # UNTESTED # factory approach my $factory = AnimalFoodFactory->new; my $food_object = $factory->prepare_correct_chow(animal=> 'lion'); # now ref $food_object eq 'LionFood'
      A factory is normally implemented as a class method ("static method" in Java parlance). You can do this then, as dragonchild pointed to above.

      my $food_object = AnimalFoodFactory->prepare_correct_chow(animal => 'lion');

      Incidentally, there's a technique for cheap aliasing of long package names that can in a pinch do some of the work of factories. Take a look at my home node.