C# › Interfaces & Abstract Classes
How would you design a class hierarchy combining an abstract base class WITH multiple interfaces to model both shared implementation AND multiple independent capabilities?
AdvancedAnswer
Combine ONE abstract base class (providing shared state/implementation for the core 'is-a' relationship) with MULTIPLE interfaces (each expressing an independent 'can-do' capability) — a class can extend exactly one abstract class while freely implementing as many interfaces as it genuinely needs, giving you the benefits of both approaches together.
public abstract class Vehicle {
public string Model { get; set; } = "";
public abstract void Start();
}
public interface IElectric { int BatteryLevel { get; } }
public interface IAutonomous { void EngageAutopilot(); }
public class Tesla : Vehicle, IElectric, IAutonomous {
public override void Start() { }
public int BatteryLevel { get; set; }
public void EngageAutopilot() { }
}Real-world example Modeling a Tesla car that shares core Vehicle behavior AND independently implements electric and autonomous-driving capabilities.