When an API allows subclassing for concrete classes without clear documentation, it violates the guideline to design and document for inheritance or prohibit it. Clear guidance helps developers extend functionality safely, prevents unpredictable subclass behavior, and keeps the API robust and maintainable.

Multiple Choice

Which guideline is violated when an API allows subclassing for concrete classes without documentation?

When an API allows subclassing for concrete classes without appropriate documentation, it violates the guideline that advises designing and documenting for inheritance or prohibiting it entirely. This guideline emphasizes the importance of clarity and transparency when designing APIs that involve inheritance. Concrete classes are typically not intended to be subclassed since they can lead to unforeseen complexities and bugs if not properly managed. When this guideline is violated, developers who interact with the API may not have a clear understanding of how to appropriately extend the functionality of the concrete classes. They could unknowingly create subclasses that behave unpredictably or introduce issues that are difficult to debug, undermining the effectiveness and reliability of the API. Proper documentation is crucial in guiding users on how to use inheritance correctly, helping them avoid pitfalls associated with subclassing. This focus on careful design and documentation ensures that the API remains robust and maintainable, allowing developers to make informed decisions when extending the functionality provided by the API.

Designing an API that includes inheritance is a delicate dance. You want to give developers enough flexibility to extend behavior without turning your codebase into a tangled forest. The key is clarity. When you let concrete classes be subclassed, you must clearly spell out how that inheritance is supposed to work, what extensions are safe, and where the boundaries lie. If you skip that, you’re inviting confusion, brittle code, and hard-to-track bugs. That’s exactly why G13—Design/document for inheritance or prohibit it—exists as a guiding principle in robust API design.

A quick gut check: why does inheritance matter in APIs at all? In many ecosystems, inheritance feels natural. It mirrors real-world hierarchies, supports polymorphism, and can reduce boilerplate by sharing common behavior. But with great power comes great responsibility. Subclassing a concrete class can bypass a lot of the safety nets developers rely on. If the base class isn’t written with extension in mind, a subclass might depend on internal assumptions, rely on fragile implementation details, or inadvertently break encapsulation. In short, without explicit documentation and careful design, a subclass can become a ticking time bomb—easy to create, hard to maintain.

Let’s unpack what this guideline really asks for and why it matters in day-to-day API work.

Clear intent and boundaries

First and foremost, an API that allows inheritance needs a clearly stated purpose. Is the base class designed to be extended, or is it primarily a plug-and-play piece of functionality? Some APIs intentionally invite extension. They offer protected hooks, virtual methods, or abstract members to guide how behavior should be customized. Others are not built for inheritance and expect you to compose behavior via delegation or mixins. The moment you expose a concrete class for subclassing, you’re signaling that extensions are a supported pattern. If you don’t provide explicit guidance on what’s safe to override, what to avoid touching, and how to reason about future changes, you’re leaving consumers in the dark. That’s a setup for compatibility surprises down the line.

Documentation as your safety net

Documentation is the bridge between intention and use. It’s not enough to say, “Subclass is allowed.” You need to map out how the subclass should interact with the base. Which methods are designed to be overridden? Which ones are sealed or final? Are there internal invariants that a subclass must preserve? Are there changes in future versions that could break subclasses? Do you require calling super methods, or can a subclass replace entire behavior? Documenting these points helps developers understand the intended extension model and reduces the likelihood of brittle subclasses that break when the library evolves.

Here’s where many teams slip up: they provide subclassing opportunities but skip the rationale. They assume that developers will read the fine print or that the examples speak for themselves. In practice, documentation tends to be skimmed or misunderstood. That’s a recipe for misalignment. If you want to empower extension without inviting chaos, you need to invest in explicit guidance—clear contracts about inheritance, examples that demonstrate safe extension, and warnings about common pitfalls.

The perils of subclassing a concrete class without guard rails

Concrete classes are concrete for a reason. They come with concrete behavior, concrete state, and concrete strategies for managing life cycles. Subclassing them can undermine those foundations in several ways:

  • Hidden dependencies: A subclass might rely on private fields or implementation details. If those details change, the subclass breaks in subtle ways. The base class shouldn’t be treated as a private toolbox for subclasses.

  • Broken invariants: Invariants that hold the base class together can be disrupted by subclass behavior, leading to inconsistent states or failed operations.

  • Fragile extensions: If the base class wasn’t designed with extension in mind, even small overrides can cascade into large, hard-to-trace issues.

  • Versioning friction: A change in the base class can force all subclasses to adapt, creating a ripple effect across downstream codebases.

All of this points to a simple truth: if you’re going to permit inheritance, you owe it to your users to spell out what that means and how to navigate it safely.

Patterns that help when inheritance is allowed

If your API design includes inheritable concrete classes, consider adopting patterns that make extension predictable and maintainable:

  • Finalize the base surface, then add controlled extension points. Mark most methods as final, but expose a handful of protected or virtual hooks where subclasses can insert custom logic.

  • Use composition over inheritance where possible. Expose behavior via interfaces or delegating components. This keeps the outer surface stable while still offering customization through interchangeable parts.

  • Provide a well-documented contract. Specify which methods are safe to override, the expectations for overrides, and any required super calls. Include examples that show both correct and incorrect usage.

  • Document the lifecycle clearly. If your object goes through phases (initialization, ready state, disposal), explain how a subclass should participate in that lifecycle without disrupting the system.

  • Introduce a sealing mechanism when appropriate. If you decide that certain classes should not be subclassed, use language features (like final classes in Java or sealed classes in newer C#) to enforce the decision, and explain the rationale in the docs.

Real-world echoes: how teams implement and communicate inheritance policies

Think about popular libraries that surface extension points. Some projects deliberately keep the extension surface small and explicit, with a clear upgrade path. Others are more permissive, but they come with a well-thumbed guidebook that developers reference when they’re unsure how to extend behavior.

A pragmatic approach is to publish a “Design for Inheritance” document within the project’s docs. It doesn’t have to read like a contract; it can be a pragmatic guide that answers common questions:

  • When should I subclass a concrete class?

  • What are the expected extension points?

  • What tests or invariants must be preserved?

  • How should I handle compatibility across versions?

  • What are the performance implications of extension?

This kind of doc becomes a living compass. It orients new contributors and helps maintainers steer the project’s evolution in a way that respects existing extensions.

Avoiding the trap of vague guarantees

One of the most tempting pitfalls is to promise extensibility without concrete guardrails. It’s the software equivalent of saying, “You can customize it however you want.” In practice, that promise translates into a lot of inconsistency, because different developers will interpret “however you want” differently. The result is a codebase where extensions collide, where subtle bugs hide behind cleverness, and where the base API feels brittle.

So, the antidote is specificity. Be explicit about:

  • What can be overridden and what cannot.

  • What the subclass is allowed to mutate and what must remain stable.

  • The expected interaction with internal state and with other components.

  • The versioning implications for changes to the extension surface.

If you can’t articulate these points clearly, you probably shouldn’t be encouraging subclassing of concrete classes. It’s better to rethink the API surface and lean into safer, more maintainable patterns.

When you might choose to prohibit inheritance

There are perfectly valid reasons to disallow subclassing in certain APIs. If the internal structure is closely tied to a particular algorithm, data layout, or resource management strategy, subclassing could easily break those guarantees. In such cases, you might prefer:

  • Making the class final or sealed to lock down subclassing.

  • Providing a robust, stable alternative that uses composition, not inheritance, to allow customization.

  • Offering well-documented extension layers (for example, strategy patterns, plug-in points, or event hooks that don’t compel subclassing).

Prohibiting inheritance isn’t about gatekeeping; it’s about preserving integrity and predictability. If the design hinges on strong invariants, sealing the class helps ensure those invariants hold, even as the surrounding ecosystem evolves.

A practical mindset for API designers

If you’re in the trenches shaping an API, here’s a mindset that often pays off:

  • Lead with intention. Before you expose an inheritance path, ask: is this extension genuinely future-proof, or is it a convenience feature that will become a maintenance headache?

  • Communicate clearly. Put the rules in black and white in the docs. Provide concrete examples, plus a few “what not to do” scenarios to illuminate the boundaries.

  • Favor explicit extension points. If you need to support customization, show exactly where and how, rather than letting developers guess.

  • Embrace evolution thoughtfully. You’re not building a static monument. Life cycles change. Design for gradual, non-breaking evolution where possible.

  • Observe and adjust. If you notice a pattern of fragile subclasses popping up in the wild, it’s a cue to reassess the extension surface and tighten the guidance.

A small, relatable analogy

Let’s imagine your API surface as a kitchen. Subclassing a concrete class is like adding a new cabinet that rearranges the layout. If the cabinet is built with clear screws, standard hinges, and a predictable mounting system, it fits nicely with the rest of the kitchen. If the cabinet is slapped in without a plan, doors misalign, and shelves wobble because the underlying structure didn’t anticipate it, you end up with a kitchen that’s hard to use and harder to fix. Clear documentation and deliberate design act like a blueprint, ensuring any new cabinet—any subclass—still harmonizes with the whole layout.

The bottom line

Inheritance is a powerful tool in API design, but it’s a tool that demands respect. If you allow concrete classes to be subclassed, you owe it to your users to provide clear guidance, explicit extension points, and a thoughtful approach to lifecycle and invariants. When you design and document for inheritance, you reduce confusion, minimize fragile extensions, and keep the API robust as it grows.

On the flip side, there are plenty of cases where inheritance simply isn’t the right path. In those cases, choosing composition, interfaces, or plug-in mechanisms can deliver flexibility without the fragility. Either way, the thread that binds all good design together is clarity. Tell developers exactly how to extend or what not to extend, and you create a healthier, more dependable ecosystem around your API.

A final thought

In the end, the real goal is a harmonious relationship between API surface and its users. Clarity about inheritance isn’t a bureaucratic constraint; it’s a design ethic that helps teams avoid stubborn bugs, embrace thoughtful evolution, and build software that stands up to real-world use. If you lead with transparency and purposeful boundaries, your API will feel reliable—like a well-tuned instrument rather than a wildcard playground. And that steadiness, more than cleverness, often wins the day.