Open lfolco opened 3 years ago
The factory methods like aSimpleProduct()
use return new static(...)
so that you can use them with a child class of the ProductBuilder
and get an object of that child class. If the child class constructor signature is not compatible though, this will break.
Can you explain your use case a bit more? I'm open to remove the final
if there's no better solution
We created a new class, CompositeProductBuilder
, that we use as a basis for composite products. Currently, even though it has the same constructor signature, it cannot extend ProductBuilder
because of the final
keyword. This in turn makes it impossible to use it in the order fixtures, etc.
Old Issue, but its quite on top and not closed yet.
Do not remove final
. Its good practice to develop classes final and use an matching Interface. If you need to have similar code, you can extend from an Abstract. Then, if you want to make a change to a Factory or whatever, just create your own class, and implement the interface or extend from the abstract. Now you can use the DI to correctly inject your instance of the factory/class/whatever.
This allows for much better code quality and as well as following the SOLID principle.
I'm working on creating composite product builders, but the use of
final
in theProductBuilder
constructor is causing issues. Would it be possible to remove that (I'll submit a PR) or is there a particular reason it's in there where the module will break if it's removed?