dimanche 27 novembre 2016

Factory Method pattern discussion

I have some ideas in my mind, would like to know your opinions. Happens that one of the big deals about Factory Method pattern is to keep Client class without knowing the Product Interface subclasses.

Usually you get two different implementations:

  1. As described above, the Client class doesn't know which Product Interface instantiate, it just delegates this task through the factory method and usually receive a String type parameter to request correct concrete product.

  2. Client class contains references to both concrete products and factory class. In this case, Client class passes a concrete product object to the factory method and form there concrete product is created.

Don't you think approach 1 is best suited with the correct description of this design patterns and also, keeps one of the main principles, keeeping Client class without knowing of concrete products?

Thoughts?

Aucun commentaire:

Enregistrer un commentaire