jeudi 29 septembre 2016

Builder Pattern more than one director

I want to know if a Builder Pattern can have more than one Director? Because I have to build a object that have different implementations.

For example,

Sometime the object is constructed from slugs so I have to use a foreach to add different slugs to object.

//Director 1

function build ($obj) {
    foreach($slugs as $slug) {
        $object = $obj->createObject($slug);
        $object->buildItem1();
        $object->buildItem2();
    }
}

But, other times the object is built out every lines.

//Director 2

function build ($obj) {
    $object = $obj->createObject();
    $object->buildItem1();
    $object->buildItem2();
}

Aucun commentaire:

Enregistrer un commentaire