Object instantiation with multiple parameters I'm trying to create a little block presenter for Laravel which displays blocks of content in certain positions. I have 2 classes, BlockFactory and Block. The BlockFactory contains all the blocks and creates them whereas the Block class is exactly just that: a simple block.

As can be seen in the code below, when I'm creating a new Block from within the BlockFactory, I have to pass all these parameters to the create method. Which then get passed onto the instantiation of the Block class and finally passed onto the constructor.

This seems very unwieldy to me. Any ideas for a smarter way of doing this?

Also: not sure if it's smart to create a new Block object inside create method. I was trying to think in terms of dependency injection but I couldn't figure it out.

// create and save new block
Block::create('name', 'content', 'position', 0, [])-&gt;add();

// BlockFactory, bound to the Block facade (bad naming i know)
class BlockFactory
{

    protected $blocks = [];
    protected $currentBlock;

    public function create($title, $content, $position, $order = 0, $parameters = [])
    {
        $this-&gt;currentBlock = new Block($title, $content, $position, $order, $parameters); // this part is bugging me somehow...
        return $this;
    }

    public function add()
    {
        $this-&gt;blocks[] = $this-&gt;currentBlock;
    }

    public function render()
    {
        return $this-&gt;blocks;
    }

}

// The actual block class
class Block
{

    protected $title;
    protected $content;
    protected $position;
    protected $order;
    protected $parameters;

    public function __construct($name, $content, $position, $order = 0, $parameters = [])
    {
        $this-&gt;title = $name;
        $this-&gt;content = $content;
        $this-&gt;position = $position;
        $this-&gt;order = $order;
        $this-&gt;parameters = $parameters;
    }
}
The problem might be the semantic reference you are using as a pattern. You are creating a class as a "factory", but the actual Factory patter is related only to creating objects, and it seems that what you mean is actually the "Repository" pattern, where you can created, manage and retrieve objects. 

And your case you would create a BlockRepository that it would be injected in the controller to be the interface between the controller and the actual blocks you need to create and retieve. 

You can find related references on the links below:


http://heera.it/laravel-repository-pattern
https://stackoverflow.com/questions/21805939/laravel-using-the-repository-pattern