Mkdir700's Note

Mkdir700's Note

架构设计

SOLID 原则详解

SOLID principles, proposed by Robert C. Martin, aim to make software design more flexible, maintainable, and scalable. The principles include Single Responsibility Principle (SRP), Open/Closed Principle (OCP), Liskov Substitution Principle (LSP), Interface Segregation Principle (ISP), and Dependency Inversion Principle (DIP). SRP emphasizes that a class should have only one reason to change, leading to clearer, more maintainable code. OCP states that entities should be open for extension but closed for modification, enhancing scalability and reducing risks. LSP focuses on ensuring that subtypes can substitute their base types without affecting program correctness. ISP suggests creating specialized interfaces rather than implementing unnecessary methods in a single interface, promoting flexibility and code reusability. DIP advocates that high-level modules should not depend on low-level modules but both should depend on abstractions, promoting decoupling and abstraction. These principles collectively improve code quality, maintainability, and system stability in software architecture design.
144
0
0
2025-03-14

常见设计模式 Python 实现

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