Background

Abstract Class vs. Interface

Master the architects of Object-Oriented Programming. Understand the blueprints, sign the contracts, and build better systems.

lightbulb The Core Difference

Abstract Class

"Is-A" Relationship (Identity)

A partial blueprint for a family of classes. It can hold shared state (fields) and common behavior. Use it when classes are closely related and share a common core identity (e.g., Dog is an Animal).

Interface

"Can-Do" Relationship (Capability)

A contract of capabilities. It defines what an object can do, regardless of its identity. Use it for unrelated classes that share a specific ability (e.g., Bird and Airplane are both IFlyable).

Blueprint
Abstract Class

The Blueprint

Think of an abstract class as a house blueprint.

  • check_circle Foundation exists: Walls and plumbing are defined (shared code).
  • check_circle Room for choice: The paint color is left blank for the owner (abstract methods).
  • check_circle Identity: A blueprint for a house builds a House, not a car.
Contract
Interface

The Contract

Think of an interface as a certification or contract.

  • check_circle Rules only: "Must be able to Fly". It doesn't say how.
  • check_circle Universal: A Bird, a Plane, and Superman can all sign this contract.
  • check_circle Multiple: You can sign many contracts (Flyable, Swimmable, Runnable).