vendredi 22 avril 2016

Dependency on factory or on created object

If i were to draw the following in a uml diagram, how would the relationship between the factory and the Validator classes look and are the MyObject and YourObject classes dependencies of the Factory class?

class Factory {

    public function create($data) {
        if ($data['type'] === 'myType') {
           return new MyObject(new ValidatorA());
        } else {
           return new YourObject(new ValidatorB());
        }
    }
}

interface Validator{
    public function validate();
}

class ValidatorA implements Validator
{
    public function validate() {
    }
}

class ValidatorB implements Validator
{
    public function validate() {
    }
}

class MyObject() {
    public function __construct(Validator $validator) {

    }
}


class YourObject() {
    public function __construct(Validator $validator) {

    }
}

Aucun commentaire:

Enregistrer un commentaire