jeudi 18 mars 2021

Does Abstract factory design pattern violate open/close principle?

Suppose we want to create button and text area.

We can whether create them for Windows or Mac.

As I understood, there are two "switch" or "if" statements, one for selecting the desired factory and one for selecting the desired product.

But if I want to add "Linux" factory and "Text field" product, should I edit the code and add this third option to the "if" or "switch" statements?

Isn't it violating the open/close principle?

Aucun commentaire:

Enregistrer un commentaire