lundi 24 juillet 2017

Inheritance in Factory Method Vs Composition in Abstract Factory Method

I am just going through the wiki pages of Factory Method Pattern and Abstract Factory method pattern.

From Head First Design Patterns I got this

Factory method Pattern uses inheritance, Abstract Factory Pattern uses composition. Abstract Factory Pattern also does the same like Factory Method Pattern which keeps the Clients decoupled from concrete Types but in a different way.

After analyzing the wiki examples, I couldn't actually find the composition in the examples. Both of the Patterns uses inheritance.

Factory Method Pattern

enter image description here

Abstract Factory Pattern

enter image description here

Here are my questions.

  1. Does Factory Method Pattern always have just only one Abstract Product inheritance tree unlike Abstract Factory Method Pattern?
  2. Where could be composition utilized or programmed in a way? If it's just the Client with main method, then Factory Method Pattern also uses Composition. A code snippet example would clear the concept.
  3. Is my interpretation of these patterns as in sample sketch correct?

Aucun commentaire:

Enregistrer un commentaire