TypeScript · Types that pay for themselves
What are abstract classes used for?
Short answer
An abstract class cannot be instantiated and can declare abstract members that subclasses must implement. It is useful when subclasses share state and behavior, unlike an interface which only describes a shape.
An abstract class is a base class that is incomplete by design. It can provide concrete methods and fields, and it can declare abstract methods that every subclass must implement. The compiler prevents direct instantiation, so the base class is only usable through a concrete subclass.
abstract class Shape {
abstract area(): number;
describe(): string {
return "Area: " + this.area().toFixed(2);
}
}
class Circle extends Shape {
constructor(private radius: number) {
super();
}
area(): number {
return Math.PI * this.radius ** 2;
}
}Abstract class, interface or concrete class
- Use an interface when you only need a shape and no shared implementation
- Use an abstract class when subclasses share state or concrete behavior
- Use a concrete class when the type is complete and can be instantiated
- A class can implement several interfaces but extend only one base class
- Abstract members are checked at compile time and have no runtime enforcement
Abstract classes are a good fit for frameworks and domain models with a genuine template method, where the base class defines the flow and subclasses fill in steps. They are a poor fit for simple data shapes, where an interface or a plain object is lighter and avoids a class hierarchy.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1When would you choose an abstract class over an interface?
- 2Can an abstract class have a constructor?
- 3Can an abstract method have an implementation?
- 4Does abstract enforce anything at runtime?
Say it in the interview
An abstract class cannot be instantiated and can define abstract methods that subclasses must implement. I use it when subclasses share state or concrete behavior, like a base Shape that provides describe while each shape implements area. If there is no shared implementation, an interface is lighter and avoids a class hierarchy. I keep the base class small so it does not become a dumping ground.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live TypeScript mock interview and get scored feedback on depth, clarity and confidence.