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;
}


Reply via email to