Mkdir700's Note

Mkdir700's Note

架构设计

SOLID 原则详解

SOLID principles, introduced by Robert C. Martin, aim to make software design more flexible, maintainable, and extensible. The Single Responsibility Principle advocates for classes to have only one reason to change, promoting clearer code and reduced coupling. The Open/Closed Principle suggests entities should be open for extension but closed for modification, enhancing code scalability and stability. The Liskov Substitution Principle emphasizes that subtypes should be substitutable for their base types, ensuring consistent inheritance hierarchy. The Interface Segregation Principle advises against forcing clients to implement unnecessary methods, increasing code flexibility and reducing coupling. Lastly, the Dependency Inversion Principle states that high-level modules should not directly depend on low-level modules, promoting abstraction and reducing coupling.
141
0
0
2025-03-14

常见设计模式 Python 实现

文章讨论了三种常见设计模式的 Python 实现。首先介绍了单例模式,通过实现一个数据库连接池管理器来说明单例模式的用法,确保系统中只有一个连接池实例。然后是工厂模式,设计一个支持多种数据格式解析的文件处理系统,包括 CSV、JSON、XML 和 YAML 格式的解析器。最后介绍观察者模式,实现股票市场监控系统,支持多种观察者类型,如邮件通知、短信通知和应用内通知。这些设计模式在软件架构设计中具有重要作用。
119
0
0
2025-03-14