vendredi 14 mai 2021

C++ Evil Getter Setter against Factory/Builder design pattern

I'm trying to learn the design pattern norme (like refacturing guru), and i have some problem to understand how i could merge the idea of bad design with public getter/setter and factory/Builder that need "out of constructor" variable setter.

for example with the answer of this article to article to Design pattern

As you can understand, each object will need a lot of informations, and adding part should set the needed informations, but to be able to do it, it need accessor to my variable outside the constructor.

Help me figure out what i'm missing.

--- Edit To be more precise, Let's say i have 2 class : CombatObject <---- Spaceships And i have a factory that will create different type of spaceships (principally because i don't want to create more than 10 class just to change the stats of the objects)

in this case, getter/setter are not a bad design (or are they?)

Aucun commentaire:

Enregistrer un commentaire