I have a class that has to be checked for being set for all of the variables, while more variables that must be set could be added:
class A{
setVar1();
setVar2();
setVar3();
}
I have to check that all three sets were called before building it. How can I create a Builder that:
A. won't have to re-call the above methods again (like implementing inside builder another setVar1() setVar2() which will call those from A - this is a hell for future maintenance to me to implement each of those setters twice). So bad example for me here would be:
class ABuilder{
build(){...}
builderSetVar1(){...} //HELL NO!
builderSetVar2(){...} //NO NO NO!!!
...
}
B. Will check before building that all must have members are set (the user of the package, won't be able to have incomplete A)
C. Will allow nested one-line building of A (Builder...SetVar1(...)....SetVar2(...).build())
Is it even possible to achieve all of those three goals? I tried too many possibilities and in every solution
All in object oriented.
Aucun commentaire:
Enregistrer un commentaire