Inheritance is a tool for sharing implementation where one class automatically gets the parent’s data and behavior, but at the cost of tight coupling. The “fragile base class” problem refers to the fact that any change in the parent can break every child.
Modern languages and framework lean more towards composition and interfaces. An interface defines the behavior, and each class implements it independently. That is, abstraction and polymorphism without inheritance.
Inheritance makes sense when there is a stable, shared implementation that multiple subclasses need, e.g.,
public abstract class BankAccount
{
protected double Balance;
public void Deposit(double amount) => Balance += amount;
public bool Withdraw(double amount)
{
if (Balance < amount) return false;
Balance -= amount;
return true;
}
public double GetBalance() => Balance;
}
public class SavingsAccount : BankAccount
{
private double _interestRate;
}
public class CheckingAccount : BankAccount
{
private int _overdraftLimit;
}
If subclasses need to override methods to provide completely different implementations, then you’re probably misusing inheritance, e.g.,
public class Car
{
public virtual void StartEngine() { /* Gasoline engine startup logic. */ }
}
public class ElectricCar : Car
{
public override void StartEngine() { /* Electric motor startup logic. */ }
}
… where we’re forcing a behavior difference into a class hierarchy, e.g., how can a hybrid car be represented?
Instead, isolate the behavior into its own abstraction and compose it, e.g.,
public interface IDriveTrain
{
void Start();
}
public class GasEngine : IDriveTrain
{
public void Start() { /* Gasoline engine startup logic. */ }
}
public class ElectricMotor : IDriveTrain
{
public void Start() { /* Electric motor startup logic. */ }
}
public class CarWithDriveTrain(IDriveTrain driveTrain)
{
public void Start() => driveTrain.Start();
}
… where a hybrid car can be represented as a car with two IDriveTrains.
- OOP Concepts | Hello Interview Low Level Design. www.hellointerview.com . Accessed Sep 14, 2026.