Conceptly
← All Concepts
πŸͺœ

Abstract Class

StructureA base class with shared behavior and extension points

An abstract class is a base class that provides some shared implementation while still leaving some required behavior for subclasses to supply. Unlike an interface, it can carry reusable code and common state along with the contract.

β–ΆArchitecture Diagram

πŸ” Structure

Dashed line animations indicate the flow direction of data or requests

Why do you need it?

When several related classes repeat the same fields and the same pre- and post-processing logic, every change has to be copied across them. But collapsing everything into one concrete class removes the places where variation should still be possible.

Why did this approach emerge?

Object-oriented frameworks and libraries often needed a way to preserve a common flow while letting user code fill in specific steps. Abstract classes became a natural tool for that job because they could combine reusable default behavior with mandatory extension points.

How does it work inside?

An abstract class can define concrete methods and fields and can also declare abstract methods that subclasses must implement. This lets the base type control the overall flow while delegating specific variations downward.

Boundaries & Distinctions

An abstract class is heavier than an interface but stronger at sharing implementation. The real dividing line is whether shared code is genuinely needed; if not, an interface is usually the cleaner contract.

When should you use it?

Abstract classes fit parsers, task runners, UI widget bases, and other families where the overall sequence stays similar but some steps vary. The risk is that as the base class accumulates more responsibility, subclasses become tightly bound to its internals.

Template method structures -- keep the common flow while subclasses fill in certain stepsRemove duplication -- centralize fields and logic shared by similar typesDefine framework extension points -- provide defaults while requiring key hooksOrganize domain hierarchies -- place common rules in a shared base