Problem Statement
When software classes are tightly coupled, hard to change, or have unclear responsibilities, the code becomes fragile and difficult to maintain. This leads to bugs, slow development, and poor scalability as the system grows.
This diagram shows how different object-oriented design principles relate: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion, connected through class and interface relationships.
### Before applying principles (violating Single Responsibility and Dependency Inversion): class Report: def __init__(self, data): self.data = data def calculate_statistics(self): # complex calculation logic pass def save_to_file(self, filename): with open(filename, 'w') as f: f.write(str(self.data)) ### After applying principles: from abc import ABC, abstractmethod class DataProcessor(ABC): @abstractmethod def calculate_statistics(self): pass class Report(DataProcessor): def __init__(self, data): self.data = data def calculate_statistics(self): # complex calculation logic pass class FileSaver(ABC): @abstractmethod def save(self, filename): pass class ReportFileSaver(FileSaver): def __init__(self, report): self.report = report def save(self, filename): with open(filename, 'w') as f: f.write(str(self.report.data))