class Employee: def __init__(self, name, salary): self.name = name self.salary = salary def calculate_pay(self): return self.salary * 0.8 # Business rule
class EmployeeDiscount(DiscountStrategy): # Extension: No existing code modified def apply(self, amount: float) -> float: return amount * 0.5
class DiscountCalculator: def calculate(self, amount: float, strategy: DiscountStrategy) -> float: return strategy.apply(amount) Subtypes must be substitutable for their base types. Deep Dive Issue: Python's duck typing hides LSP violations. A subclass might accept different argument types or raise unexpected exceptions.
from abc import ABC, abstractmethod class MessageSender(ABC): # Abstraction @abstractmethod def send(self, message: str) -> None: pass
def save_to_db(self): print(f"Saving self.name to DB") # Persistence
class Scanner(Protocol): def scan(self, doc: str) -> None: ...
class Bird: def fly(self, altitude: int) -> None: return f"Flying at altitude" class Penguin(Bird): def fly(self, altitude: int) -> None: # Violation: Changes pre-condition (cannot fly) raise NotImplementedError("Penguins can't fly")


