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

Document which classes support inheritance and which do not #938

Open
1 task
jbduncan opened this issue Jul 11, 2017 · 8 comments
Open
1 task

Document which classes support inheritance and which do not #938

jbduncan opened this issue Jul 11, 2017 · 8 comments

Comments

@jbduncan
Copy link
Contributor

jbduncan commented Jul 11, 2017

Overview

Currently, AFAICT, no classes (apart from utilities classes) document their support for inheritance (that is, whether they are designed to be subclassed or not). Effective Java 2nd edition, Item 16 describes the dangers of allowing users and extension writers to subclass JUnit 5 classes that aren't designed for inheritance. Therefore we should follow Item 17's advice to prevent this.

Specifically, each class should meet the following criteria (more or less ripped from the book):

  1. For classes that support inheritance:
    1. Make those methods which aren't intended to be overridden final.
    2. The class must document it's self-use of overridable methods.
    3. To allow programmers to write efficient subclasses without undue pain, a class may have to provide hooks into its internal workings in the form of judiciously chosen protected methods or fields.
    4. The only way to test a class designed for inheritance is to write subclasses; classes must be tested by writing subclasses before releasing it. (Before GA, in our case.)
    5. Constructors must not invoke overridable methods.
    6. For classes implementing Cloneable or Serializable, neither clone nor readObject may invoke an overridable method, directly or indirectly.
  2. For classes that don't support inheritance:
    1. Prohibit subclassing by making the class final or replacing all public constructors with public static factory methods.

Deliverables

  • Each and every class meets the criteria above.
@sbrannen
Copy link
Member

slated for RC1 for team discussion

@sbrannen sbrannen modified the milestones: 5.0 RC1, 5.0 GA Jul 29, 2017
@marcphilipp marcphilipp modified the milestones: 5.0 GA, 5.1 Backlog Sep 7, 2017
@stale
Copy link

stale bot commented May 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label May 13, 2021
@jbduncan
Copy link
Contributor Author

I'd still like for this to be addressed at some point.

@stale stale bot removed the status: stale label May 13, 2021
@jbduncan
Copy link
Contributor Author

That being said, I understand if some classes/methods can't be made final now for backward-compatibility reasons, but at the very least each and every public class and method should be documented appropriately.

@marcphilipp
Copy link
Member

We have done so in a few places, e.g.:

* <p>This interface is not intended to be implemented by clients.

* <p>This class is not intended to be extended by clients.

@jbduncan Is this something you think you could contribute via a PR?

@jbduncan
Copy link
Contributor Author

jbduncan commented Jun 3, 2021

@marcphilipp Oh, excellent!

I've also seen that this file has some inheritance-related info:

* <p>Although it is technically possible to extend this class, extension is
* strongly discouraged. The JUnit Team highly recommends that the methods
* defined in this class be used via <em>static imports</em>.

Yes, I'd love to raise a PR, but I'm currently juggling a PR for junit-pioneer and some real life commitments, so I've put this issue on my TODO list. :)

@marcphilipp marcphilipp removed this from the 5.x Backlog milestone Jun 19, 2021
@stale
Copy link

stale bot commented Jun 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label Jun 21, 2022
@jbduncan
Copy link
Contributor Author

jbduncan commented Jul 1, 2022

I'm still interested in contributing this eventually.

@stale stale bot removed the status: stale label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants