Show in graph

Software → Software Design

Inheritance

An object-oriented mechanism where one type derives behavior or structure from another.

Brief explanation

Inheritance models an is-a relationship and lets specialized classes reuse or refine behavior from a common base. It is useful when the hierarchy is real and stable, but it becomes harmful when used only to share code between things that are not actually the same kind of object.

Code example
Bad example
Python
class EmailNotifier:  def notify(self, message: str) -> None:      print(f"Email: {message}")class OrderService(EmailNotifier):  def checkout(self, total: float) -> None:      print(f"Charging: {total}")      self.notify("Order confirmed")
Good example
Python
from abc import ABC, abstractmethodclass Notifier(ABC):  @abstractmethod  def notify(self, message: str) -> None:      ...class EmailNotifier(Notifier):  def notify(self, message: str) -> None:      print(f"Email: {message}")class OrderService:  def __init__(self, notifier: Notifier):      self.notifier = notifier  def checkout(self, total: float) -> None:      print(f"Charging: {total}")      self.notifier.notify("Order confirmed")