Quick revision
The short answer
The breakages come from the fragile base class problem: when 40 teams extend our classes, their code depends on our implementation details, which methods call which and when, so any internal change can break them. I would move to interfaces plus composition, where teams supply small strategies or callbacks and the framework owns the flow; keep the few remaining base classes with final template methods, documented self-use and a handful of protected hooks; use sealed hierarchies where the set of variants is closed; and migrate through adapters with a published deprecation timeline.
What to remember
In this answer, we saw that changes to widely extended base classes break teams because subclasses depend on self-use, the way the base class calls its own methods. We redesigned the model so the framework owns the flow in final classes and teams provide narrow strategies and callbacks, hardened the remaining base classes with final template methods, documented hooks and minimal protected surface, used sealed hierarchies for closed sets of variants, and planned a gradual migration through adapters, deprecation, a published timeline and an adoption count.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The breakages come from the fragile base class problem: when 40 teams extend our classes, their code depends on our implementation details, which methods call which and when, so any internal change can break them. I would move to interfaces plus composition, where teams supply small strategies or callbacks and the framework owns the flow; keep the few remaining base classes with final template methods, documented self-use and a handful of protected hooks; use sealed hierarchies where the set of variants is closed; and migrate through adapters with a published deprecation timeline.
Why this question is asked
Internal frameworks often start with abstract base classes because they are the quickest way to share code: write AbstractJob, let teams extend it, and override what they need. It works while there are three users. At 40 teams, every change to the base class is a breaking change for somebody, releases slow down, and teams start pinning old versions. Interviewers ask this design question to see whether we can explain why inheritance fails at scale and redesign an extension model without stopping 40 teams' work. In this answer, we will see the fragile base class problem in code, design a composition-based model, harden what remains of inheritance, decide where sealed types help, and plan the migration.
1Why Every Base Class Change Breaks Someone
A subclass does not depend only on the public methods of its parent. It depends on how the parent uses its own methods internally, which is called self-use. If the base class calls process() from inside run(), and a team overrides process(), that team now depends on that internal call. When we refactor run() to call process() twice, or not at all, their code breaks even though no public signature changed.
Notice that nobody did anything wrong by the usual rules. The team overrode a protected method we offered, and we changed the body of a method without changing its signature. The problem is structural: protected methods and self-use are part of the contract with subclasses whether we meant them to be or not. With 40 teams, someone always depends on the detail we change.
2Option 1: The Framework Owns the Flow, Teams Supply Parts
The main fix is to invert the relationship. Instead of teams extending our class and inheriting our flow, the framework owns the flow in a final class, and teams provide small objects that implement narrow interfaces, often functional interfaces that a lambda can implement. This is composition: the framework has a reference to the team's code instead of the team's code being a kind of framework class.
6 messages in order. Play them, or step through them one at a time.
Everything inside JobRunner can change; only the interfaces are shared.
Now the contract with teams is exactly the interfaces: one method in JobStep, two optional callbacks in JobListener. We can change everything inside JobRunner, add retries, metrics or tracing, without breaking anyone, because no team code depends on how run() is written. Notice that retrying is now an explicit choice, RetryPolicy, so the team that sends emails can say none and keep its behaviour.
3Option 2: Where Base Classes Stay, Make Them Safe
Some base classes are worth keeping, for example when migration cost is high or the shared behaviour is large. Then we harden them, using the template method pattern deliberately. A template method is a method that defines the steps of an algorithm and calls hook methods for the parts that vary. We make the template method final, so the flow cannot be overridden, expose only specific protected hooks with documented contracts, and make every other method private or final.
The Javadoc on each hook documents the self-use: when it is called and how often. That turns an accident into a promise we know we must keep. Fewer hooks mean fewer promises, so each one should be justified by a real need from several teams.
4Option 3: Sealed Hierarchies for Closed Sets
Some hierarchies are not meant to be extended by teams at all. If the framework supports exactly three kinds of trigger, schedule, event and manual, a sealed interface states that in code: sealed interface Trigger permits Schedule, Event, Manual. No team can add a fourth, so the framework can handle every case with an exhaustive switch, and adding a variant is a deliberate framework release instead of something any team can do. Sealed types are the right tool for closed sets of variants; interfaces with composition remain the tool for open extension.
| Mechanism | Who adds variants | What we can change freely |
|---|---|---|
| Open abstract base class | any team, any method | almost nothing |
| Hardened base class | teams, via documented hooks | everything except hook contracts |
| Interfaces plus composition | teams, via narrow interfaces | the whole flow |
| Sealed hierarchy | only the framework team | variants, in a planned release |
5Migrating 40 Teams Without a Flag Day
The migration must let teams move at their own pace. The first step is an adapter: a class that lets old subclasses run on the new model, for example an AbstractJobAdapter that implements JobStep by calling the old process(). We then ship the new API alongside the old one, mark the base classes @Deprecated with a pointer to the replacement, and publish a timeline, such as new API in release 5.0, deprecation warnings in 5.2, removal in 6.0, twelve months later.
Then we make migration cheap: a short guide with before and after code, automated refactoring recipes where the change is mechanical, and office hours for the hard cases. We track adoption with a simple count of classes in each repository that still extend the deprecated base classes, and we talk to the last few teams directly rather than surprising them at removal. Notice that we never break teams during the transition: old and new run together until the count reaches zero.
6Follow-up questions
Is inheritance ever the right choice for a shared framework?
Yes, when the base class is designed and documented for extension, the hooks are few and stable, and the framework team is prepared to treat them as a public API forever. Test base classes that only offer setup helpers are a common acceptable example. The problem is open-ended inheritance across team boundaries, where implementation details become contracts by accident.
How do you stop teams depending on internals again in the new model?
Keep the implementation classes final and package-private where possible, expose only interfaces from an api package, and use the module system or architecture tests such as ArchUnit rules to fail builds that import internal packages. What teams cannot reach, they cannot depend on.
7Conclusion
In this answer, we saw that changes to widely extended base classes break teams because subclasses depend on self-use, the way the base class calls its own methods. We redesigned the model so the framework owns the flow in final classes and teams provide narrow strategies and callbacks, hardened the remaining base classes with final template methods, documented hooks and minimal protected surface, used sealed hierarchies for closed sets of variants, and planned a gradual migration through adapters, deprecation, a published timeline and an adoption count.
Open with
The root cause is the fragile base class problem. When teams extend our abstract classes, they depend not just on the public methods but on how the base class calls its own methods internally, the self-use.
Then, if they want more
So even a change that keeps every signature, like adding retries inside run, can break a subclass. With 40 teams, someone always depends on the detail we change. My redesign would invert the relationship: the framework owns the flow in final classes, and teams plug in small interfaces, strategies or callbacks, often functional interfaces they implement with a lambda.
Then the only contract is those interfaces, and we can change everything inside the runner. Where a base class has to stay, I would make the template method final, expose only a few protected hooks, document exactly when each hook is called, and make everything else private or final.
For things that are a closed set, like the kinds of triggers the framework supports, I would use a sealed interface so only the framework adds variants and switches are exhaustive.
For the migration, I would provide adapters so old subclasses run on the new model, ship both APIs, deprecate the base classes with a clear timeline, help teams with guides and automated refactoring, and track how many classes still extend the deprecated types until that number reaches zero.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your shared framework exposes abstract base classes that 40 internal teams extend. Every...": https://scrivio-interview-library.netlify.app/java/oop-principles/f5233550c2/