mercredi 17 juin 2015

Factory method - how to improve this

class MyConcreteFactory
{
    public static function create($model, $typeId)
    {
        if ($typeId == 'customer') {
            return new CustomerWrapper($model);
        }
        if ($typeId == 'order') {
            return new OrderWrapper($model);
        }
        if ($typeId == 'product') {
            return new ProductWrapper($model);
        }
    }
}

How can i improve this? The main flaw is that managing the typeId checking logic will need changed every time a new entity type is introduced or changed.

Aucun commentaire:

Enregistrer un commentaire