Mkdir700's Note

Mkdir700's Note

架构设计

SOLID 原则详解

SOLID principles, proposed by Robert C. Martin, aim to make software design more flexible, maintainable, and extensible. The Single Responsibility Principle emphasizes that a class should have only one reason to change, leading to clearer and more testable code. The Open/Closed Principle promotes extending code rather than modifying it, enhancing scalability and stability. The Liskov Substitution Principle ensures that subclasses can replace their base classes without affecting program correctness, maintaining consistency and reliability. The Interface Segregation Principle advocates for smaller and focused interfaces to improve flexibility and reusability. Finally, the Dependency Inversion Principle suggests that high-level modules should not depend on low-level modules, both of which should depend on abstractions rather than details, achieving reduced coupling and increased maintainability.
46
0
0
2025-03-14

常见设计模式 Python 实现

本文介绍了常见的设计模式在 Python 中的实现,包括单例模式、工厂模式和观察者模式。单例模式中实现了一个数据库连接池管理器,确保系统中只有一个连接池实例,连接池应支持获取连接和释放连接的功能。工厂模式设计了一个支持多种数据格式解析的文件处理系统,系统能处理 CSV、JSON、XML 和 YAML 格式的文件,并将它们转换为统一的内部数据结构。观察者模式实现了一个股票市场监控系统,能通知注册的观察者股票价格变化的情况。这些设计模式提供了灵活性和可扩展性,有助于优化代码结构与功能实现。
28
0
0
2025-03-14