Mkdir700's Note

Mkdir700's Note

架构设计

SOLID 原则详解

SOLID principles, introduced by Robert C. Martin, aim to make software design more flexible, maintainable, and scalable. The Single Responsibility Principle advocates for classes having a single responsibility to avoid coupling. The Open/Closed Principle emphasizes extending existing code rather than modifying it to add new features. The Liskov Substitution Principle focuses on maintaining consistency in inheritance hierarchies. The Interface Segregation Principle suggests using specialized interfaces over general ones to enhance flexibility. Lastly, the Dependency Inversion Principle promotes high-level modules depending on abstractions, not concrete details, to reduce coupling. These principles lead to clearer, more maintainable code and improved system stability.
145
0
0
2025-03-14

常见设计模式 Python 实现

本文介绍了单例模式、工厂模式和观察者模式的Python实现。单例模式通过一个数据库连接池管理器示例说明了确保系统中只有一个连接池实例。工厂模式展示了设计一个多种数据格式解析的文件处理系统,包括CSV、JSON、XML和YAML文件格式的解析器。观察者模式则通过股票市场监控系统示例说明了如何在股票价格变化时通知多种观察者。这些设计模式有助于构建灵活可维护的系统。
122
0
0
2025-03-14