mercredi 24 octobre 2018

Setting object values in php factory or factory method

I have a little question, is setting values in factory method correctly ?

Something like this:

class ObjectFactory {
     public static function create($config)
     {
          $object = new Object();
          $object->setDependency(// something);
          $object->setValue(// something);
          return $object;
     }
}

Is it correctly? Maybe it should be builder? How should i call it? ObjectBuilder, ObjectFactory, or maybe ObjectCreator?

Please explain me cases of creating object with some dependencies or initial values. I know it should be builder pattern but i heard that builder is something advanced than just returning object with few initial values or dependencies. So... what's the solution?

Aucun commentaire:

Enregistrer un commentaire