O
O
Outsider V.2015-07-30 13:04:59
PHP
Outsider V., 2015-07-30 13:04:59

Is it correct to pass the required objects as method arguments?

There are classes Controller and Saver. The controller in the method creates an EntrySaver by passing it to the constructor from its Request and Response properties. Then it pulls various saver methods, after which (if the methods returned the desired values) it runs the $saver->save() method...
But! To save the data (they are passed in the Request object), the saver needs two more objects - ObjectFacroty and Assembler. Is it okay to pass these objects to the ->save() method, or should we pass them at the very beginning - to the saver constructor?

class Controller
{
    ...
    public function add()
    {
            ...
            $saver = new Saver($this->request, $this->response);
            ...
            $saver->check();
            ...
            $saver->save($this->p_factory->getObjectFactory(), $this->factory->getAssembler());
            ...
    }
    
    ...
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wol_fi, 2015-07-30
@wol_fi

Yes, it doesn’t matter, objects are still passed by reference, so it’s impossible to gain in the resources spent here. Well, if the objects are used only in one method, and are not the state of the root object, then yes, I would pass them as method parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question