You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on creating composite product builders, but the use of final in the ProductBuilder 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?
The text was updated successfully, but these errors were encountered:
lfolco
changed the title
Use of final in ProductBuilder
Use of "final" in ProductBuilder constructor
Jan 25, 2021
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?The text was updated successfully, but these errors were encountered: