I have an Order class for tracking user orders. It has methods like create_db_record and update_db_record. In considering a function fetch_db_record_by_id, I'm thinking that rather than instantiating a blank object and then using the fetch method, I should instead define a static method that returns an instance of the class. Is that a reasonable thing to do? Also, is this considered a factory pattern or not? I'm under the impression that a factory pattern is used when one isn't really sure what type of class to instantiate.
for example:
class Order {
public function __construct($arr) {
foreach($arr as $key => $value) {
$this->$key = value;
}
}
public static function fetch($id) {
// imagine that db query and fetch assoc populates $row here
return new static($row);
}
}
I have not tested this. Just wondering if it's a sane thing to do or not.