mercredi 10 novembre 2021

Control flow Factory Abstract pattern

I saw this diagram which is the "Factory Abstract" pattern. It allows to create a concrete object in an "abstract world" without having source code dependencies. I guess they are many ways to explain it, and all the explication I read didn't help me.

I understand the application has 2 interface : "Service Factory" and "Service". "Service Factory" implements a function which all class who inherits from this interface will have to apply (here begins dependency inversion n°1). "Service Factory Impl" is a concrete class which has to implement the function. The function will create a concrete class (I assume "Concrete Impl" has a constructor and it call it in makeSvc function).

As I understand, the control flow begins in "Application" when it calls the function "makeSvc". It goes through "Service Factory" -> "Service Factory Impl". And then I don't understand. It goes back to "Service" and after "Concrete Impl" ?

  1. When is the constructor of "Concrete Impl" called ?
  2. Why does all of this end up with a "Service" (meaning, after all the process the application will have a "Service") ?
  3. What does makeSvc() contain ? I guess at least the "Concrete Impl" constructor ?

If someone could detail the control flow, it would be really helpful.

Thanks.

enter image description here

Aucun commentaire:

Enregistrer un commentaire