Hi
This is probably a really straightforward answer - but a bit of advice would be appreciated.
I have a small system where all of my objects use the same load() and loadMultiple() methods. Exactly the same code in each. Very simple, example below.
public static function load($id) {
// Instantiate the object
$object = new self($id);
return $object;
}
The example code above can't go in an interface obviously, but neither can it go in an abstract class as I am instantiating the object (same in the loadMultiple method).
What is the most elegant solution to this? I am currently planning to create a parent class such as:
class Object_Model {
public function load() {
// Code here
}
public function loadMultiple() {
// Code here
}
}
class Object1 extends Object_Model {
}
class Object2 extends Object_Model {
}
But I am sure there must be a better way. Is there?