Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of "final" in ProductBuilder constructor #65

Open
lfolco opened this issue Jan 25, 2021 · 3 comments
Open

Use of "final" in ProductBuilder constructor #65

lfolco opened this issue Jan 25, 2021 · 3 comments
Labels

Comments

@lfolco
Copy link
Contributor

lfolco commented Jan 25, 2021

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?

@lfolco lfolco changed the title Use of final in ProductBuilder Use of "final" in ProductBuilder constructor Jan 25, 2021
@schmengler
Copy link
Collaborator

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

@lfolco
Copy link
Contributor Author

lfolco commented Sep 13, 2021

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.

@bytes-commerce
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants