Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Disallow inheritance from ProgressBar #20487

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

Closed
wants to merge 2 commits into from
Closed

[Console] Disallow inheritance from ProgressBar #20487

wants to merge 2 commits into from

Conversation

a-ast
Copy link
Contributor

@a-ast a-ast commented Nov 11, 2016

Q A
Branch? "master"
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20427
License MIT
Doc PR ~

Changed ProgressBar to final, fixed tests.
As explained below, this modification doesn't break BC because inheritance from ProgressBar was not possible anyway.
See: #20427

@unkind
Copy link
Contributor

unkind commented Nov 11, 2016

Can you explain your use-case when you need to inherit the ProgressBar? It could help to improve the ProgressBar itself.

@stof
Copy link
Member

stof commented Nov 11, 2016

the right fix would be to re-bind the closure explicitly to the right class instead. Switching to protected makes the method accessible (and overwritable) in child class, and so impacts the API covered by BC, which is a no-go.

@unkind
Copy link
Contributor

unkind commented Nov 11, 2016

If it doesn't work right now, it won't be a BC break to finalize the class. It just depends on use-cases.

@GuilhemN
Copy link
Contributor

GuilhemN commented Nov 11, 2016

@unkind indeed it is not a bc break, but it will add stuff to maintain because of sf's bc policy which is avoided when possible.

@unkind
Copy link
Contributor

unkind commented Nov 11, 2016

@unkind indeed it is not a bc break, but it will add stuff to maintain because of sf's bc policy which is avoided when possible.

final makes keeping BC easier, what do you mean?

@a-ast
Copy link
Contributor Author

a-ast commented Nov 11, 2016

Can you explain your use-case when you need to inherit the ProgressBar?

@unkind I performed some experiments, but my ideas didn't work because of this issue with inheritance. So, at the end I have no real use case, because I went with another approach.

However, my point is: either ProgressBar class must be final or inheritance must be supported, isn't it?

@GuilhemN
Copy link
Contributor

@unkind of course sorry, I didn't understand well what you meant.

I agree with you and I think we should consider make more classes final unless people prove that extending them brings real benefits. Here as this helper is unlikely to be worth being extended, I would be for final.
However, I think it's safer to deprecate extending it for 4.0 (it's really simple) as the error doesn't happen as long as you don't call a method of the helper.

@xabbuh
Copy link
Member

xabbuh commented Dec 3, 2016

So do I understand correctly that extended the class does only work as long as you do not call the start() method?

@a-ast
Copy link
Contributor Author

a-ast commented Dec 3, 2016

@xabbuh yes

@xabbuh
Copy link
Member

xabbuh commented Dec 3, 2016

In this case declaring the class as final should be valid.

@a-ast
Copy link
Contributor Author

a-ast commented Dec 3, 2016

BC Promise disallows to make classes final.
What should I do to make such change in 4.0?

ping @nicolas-grekas, @fabpot
The issue is very simple: ProgressBar is not final, but extending it (even if it is the weird idea) causes Fatal error after calling start().

@GuilhemN
Copy link
Contributor

GuilhemN commented Dec 3, 2016

@a-ast #20493 allows to do this by using the @final annotation.

@nicolas-grekas
Copy link
Member

Does it always throw? This would mean nobody could have extended the class, so making it final would be safe.

@a-ast
Copy link
Contributor Author

a-ast commented Dec 3, 2016

@nicolas-grekas yes, it throws always.
It seems that I need to wait until #20493 is merged to continue with my PR, isn't it?

@unkind
Copy link
Contributor

unkind commented Dec 3, 2016

@a-ast I fail to see how #20493 blocks you. As already mentioned, final doesn't break BC anyway in this specific case.

@GuilhemN
Copy link
Contributor

GuilhemN commented Dec 3, 2016

#20493 was only needed in case we considered this change as a bc break. As we don't, you can just directly make the class final.

@a-ast a-ast closed this Dec 4, 2016
@a-ast a-ast reopened this Dec 4, 2016
@a-ast a-ast closed this Dec 4, 2016
@a-ast a-ast reopened this Dec 4, 2016
@a-ast
Copy link
Contributor Author

a-ast commented Dec 4, 2016

doesn't break BC anyway in this specific case.

@unkind, @GuilhemN thank you for explanation.
I made the class final and it appeared that some tests failed because they mocked the class to spy on display method.
I've changed the implementation of this tests. Maybe it is not as elegant as before, but, on the other hand, now it is simpler and without mocking.

@a-ast a-ast changed the title [Console] Allow inheritance from ProgressBar [Console] Disallow inheritance from ProgressBar Dec 4, 2016
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@fabpot
Copy link
Member

fabpot commented Dec 13, 2016

Thank you @a-ast.

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

Successfully merging this pull request may close these issues.

8 participants