Update AV1004: Use an interface rather than a base class to support multiple implementations#346
Open
dennisdoomen wants to merge 1 commit intodevelopfrom
Open
Update AV1004: Use an interface rather than a base class to support multiple implementations#346dennisdoomen wants to merge 1 commit intodevelopfrom
dennisdoomen wants to merge 1 commit intodevelopfrom
Conversation
Split from #298. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bkoelman
reviewed
Mar 29, 2026
| severity: 3 | ||
| --- | ||
| If you want to expose an extension point from your class, expose it as an interface rather than as a base class. You don't want to force users of that extension point to derive their implementations from a base class that might have an undesired behavior. However, for their convenience you may implement a(n abstract) default implementation that can serve as a starting point. | ||
| If you want to expose an extension point from your class, expose it as an interface rather than as a base class. You don't want to force users of that extension point to derive their implementations from a base class that might have an undesired behavior. However, for their convenience you may implement an abstract default implementation that can serve as a starting point. |
Collaborator
There was a problem hiding this comment.
Suggested change
| If you want to expose an extension point from your class, expose it as an interface rather than as a base class. You don't want to force users of that extension point to derive their implementations from a base class that might have an undesired behavior. However, for their convenience you may implement an abstract default implementation that can serve as a starting point. | |
| If you want to provide an extension point for your class, expose an interface rather than a base class. You don't want to force alternative implementations to derive from your base class that might have an undesired behavior. However, for their convenience, you may provide an abstract default implementation as a starting point. |
Though I believe the last sentence is almost always a bad idea. And #302 advocates against it for a good reason:
Any change to the base class can unexpectedly break derived classes, and the inheritance hierarchy can become difficult to understand as it grows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates guideline AV1004.
It was split out of #298 so the change can be reviewed independently.
Files:
Part of the replacement for #298.