lundi 7 novembre 2016

Using factory pattern for various components/modules

Let's say we have a system that builds articles. The article has some components validator, cleaner, storage.... In the client to build an article I have to instantiate each component:

new validator(parameters...) new cleaner(parameters...) new storage(parameters...)

Without these it's impossible to build an article.

My question is: Can I use the factory pattern to create all of these like this:

class ArticleFactory
{
    public function createArticle(): ArticleInterface
    {
        return new Article();
    }

    public function validator(): ValidatorInterface
    {
        return new Validator();
    }

    public function cleaner(): CleanerInterface
    {
        return new Cleaner();
    }

    public function storage(): StorageInterface
    {
        return new Storage();
    }
}

So as in the client is more convenient to create an article? Or is this violates any of the SOLID principles

Aucun commentaire:

Enregistrer un commentaire