I really like this example too, though it lacks a class method example: if(DOG::number_of_dogs_in_the_pound() > 1){ foreach my $dog (@Pound){ if($dog->is_male()){ print "I though so"; } } }
Sorry, I couldn't resist after that female comment. Marilyn On Thu, Jan 29, 2009 at 10:56 AM, André Warnier <a...@ice-sa.com> wrote: > Michael Peters wrote: > >> kropotkin wrote: >> >> In general is it better to use a class method or object method? >>> >> >> It depends on what you're using it for and how. Does the method act on any >> instance specific state data? Or does it act on class specific data? >> >> A more concrete example would be a Dog class. Is bark() a method on Dog or >> $fido? Well, every dog, no matter it's name is going to bark the same. Is >> eat() a method on Dog or $fido? Well, if eat() changes $fido's >> next_poop_interval property, then obviously it needs to be an instance >> method. >> >> This is a great example. :-) > > And of course, if your system is only every going to have 1 Dog then you >> don't need to ever have instances, right? >> >> if ($Dog::is_female()) { > err on the side of caution && instantiate it nevertheless; > } > > >