Mkdir700's Note

Mkdir700's Note

架构设计

SOLID 原则详解

SOLID principles, including Single Responsibility Principle (S), Open/Closed Principle (O), Liskov Substitution Principle (L), Interface Segregation Principle (I), and Dependency Inversion Principle (D), aim to improve software design flexibility, maintainability, and scalability. For example, the Single Responsibility Principle emphasizes that a class should have only one reason to change, leading to clearer, more maintainable code. The Open/Closed Principle promotes extensibility over modification by using abstraction and polymorphism. The Liskov Substitution Principle ensures that subtypes can replace their base types without affecting program correctness, maintaining consistency and reliability in the inheritance hierarchy. The Interface Segregation Principle advocates for clients not to depend on interfaces they don't use, enhancing code flexibility and reducing coupling. Finally, the Dependency Inversion Principle suggests that high-level modules should not directly depend on low-level modules, promoting abstraction and dependency injection for decoupling. These principles collectively contribute to better software architecture and development practices.
131
0
0
2025-03-14

常见设计模式 Python 实现

这篇文章介绍了三种常见的设计模式在Python中的实现:单例模式、工厂模式和观察者模式。在单例模式中,通过创建一个全局唯一的连接池实例来管理数据库连接,确保系统中只有一个实例。工厂模式实现了一个文件处理系统,支持多种文件格式的解析器,并根据文件扩展名创建对应的解析器。观察者模式实现了一个股票市场监控系统,当股票价格变化时通知注册的观察者,包括邮件通知、短信通知和应用内通知。这些设计模式在实际应用中有着广泛的应用,有助于提高系统的灵活性和可维护性。
111
0
0
2025-03-14