Mkdir700's Note

Mkdir700's Note

架构设计

SOLID 原则详解

SOLID principles, introduced by Robert C. Martin, aim to improve flexibility, maintainability, and scalability in software design. The Single Responsibility Principle advocates that a class should have only one reason to change, promoting clearer, more maintainable code. The Open/Closed Principle encourages extending existing code rather than modifying it, enhancing scalability and reducing risks. The Liskov Substitution Principle ensures that subclasses can replace their base classes without affecting program correctness, maintaining consistency and reliability. The Interface Segregation Principle suggests using multiple specific interfaces over a single broad interface, increasing flexibility and clarity. The Dependency Inversion Principle states that high-level modules should not directly depend on low-level modules, promoting abstraction and reducing coupling. By adhering to these principles, code becomes clearer, more flexible, and easier to maintain.
136
0
0
2025-03-14

常见设计模式 Python 实现

本文介绍了三种常见的设计模式在 Python 中的实现,分别是单例模式、工厂模式和观察者模式。在单例模式中,通过实现一个数据库连接池管理器,确保系统中只存在一个连接池实例,并支持获取连接和释放连接的功能。在工厂模式中,设计一个支持多种数据格式解析的文件处理系统,包括 CSV、JSON、XML 和 YAML 格式的文件解析,通过工厂类创建对应的解析器。在观察者模式中,实现一个股票市场监控系统,当股票价格变化时通知注册的观察者,包括邮件通知、短信通知和应用内通知等多种观察者。这些设计模式在软件架构设计中起到了重要作用。
116
0
0
2025-03-14