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 (S) states that a class should have only one reason to change, promoting clearer, more maintainable code. The Open/Closed Principle (O) advocates for software entities to be open for extension but closed for modification, enhancing code scalability and stability. The Liskov Substitution Principle (L) guides subclassing to ensure it can replace its base class without affecting program correctness, maintaining consistency and reliability. The Interface Segregation Principle (I) suggests that clients should not be forced to implement interfaces they do not use, promoting flexibility and reducing coupling. The Dependency Inversion Principle (D) emphasizes that high-level modules should not directly depend on low-level modules, but both should depend on abstractions, promoting decoupling and flexibility in software design.
116
0
0
2025-03-14

常见设计模式 Python 实现

该文章介绍了三种常见的设计模式在Python中的实现,分别是单例模式(Singleton Pattern)、工厂模式(Factory Pattern)、观察者模式(Observer Pattern)。在单例模式中,通过实现一个`DatabaseConnectionPool`类来管理数据库连接池实例,确保全局唯一连接池,并支持获取和释放连接的功能。工厂模式则是设计一个`FileParser`抽象基类和具体解析器类,以及一个`ParserFactory`工厂类,根据文件扩展名创建对应的解析器。最后,在观察者模式中,通过实现`Subject`接口、`StockMarket`类管理股票价格并通知观察者,包括`EmailNotifier`、`SMSNotifier`和`AppNotifier`三种不同类型的观察者。这些设计模式为软件架构提供了灵活、可维护和可扩展的设计解决方案。
101
0
0
2025-03-14