Skip to content

Update AV1004: Use an interface rather than a base class to support multiple implementations#346

Open
dennisdoomen wants to merge 1 commit intodevelopfrom
copilot/pr298-update-av1004
Open

Update AV1004: Use an interface rather than a base class to support multiple implementations#346
dennisdoomen wants to merge 1 commit intodevelopfrom
copilot/pr298-update-av1004

Conversation

@dennisdoomen
Copy link
Copy Markdown
Owner

This PR updates guideline AV1004.

It was split out of #298 so the change can be reviewed independently.

Files:

  • _rules/1004.md

Part of the replacement for #298.

Split from #298.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants