Course contentsShow
← TypeScript
Lesson 1048 of 1,79624. Classes in TypeScriptFree lesson

Abstract Class Basics

Using the abstract keyword to define classes that cannot be instantiated directly.

Abstract Class Basics

You'll learn: How to use the abstract keyword to create base classes that define a contract but cannot be directly instantiated.

What Are Abstract Classes?

An abstract class is a special kind of class that serves as a blueprint for other classes but cannot be instantiated on its own. Think of it like an architectural plan for a house: it defines what rooms must exist and what features are required, but you can't actually live in the plan itself—you need to build a concrete house from it first.

The Core Idea

When you mark a class as abstract, TypeScript enforces two key rules:

  1. You cannot create instances of the abstract class directly — you must create subclasses that extend it
  2. You can define abstract methods that subclasses must implement

This gives you a middle ground between interfaces (which have no implementation) and regular classes (which are fully concrete). Abstract classes let you provide some shared implementation while requiring subclasses to fill in the specific details.

Why Use Abstract Classes?

Abstract classes are perfect when you have a family of related classes that share common behavior but differ in certain specifics. For example, all payment processors might share logging logic, but each one (Stripe, PayPal, etc.) processes payments differently. The abstract class captures the commonality while enforcing that subclasses provide the unique parts.

Comparing to Interfaces

Unlike interfaces, abstract classes can contain actual implementations, constructor logic, and properties with values. They're more powerful than interfaces but more rigid—you can only extend one abstract class, whereas you can implement multiple interfaces.

Key Takeaway: Abstract classes use the abstract keyword to create base classes that provide shared functionality while preventing direct instantiation, forcing developers to create concrete subclasses instead.