套用各种DP写一个系统,跑起来了,但后来发现真有变化来临的时候想扩展还得大规模改动甚至重写,这就是传说中的DP乱套了,达不到效果反而徒增工作量,内心惭愧,于是细读OO大师的设计信条,才慢慢明晓DP要怎么样实作才能真正达到效果,记下六大原则原文,肃清乱套之风,以作警戒。
Single Responsibility Principle: There should never be more than one reason for a class to change.
Open Closed Principle: Software entities like classes, modules and functions should be open for extension but closed for modifications.
Liskov Substitution Principle: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
Law of Demeter: Least Knowledge Principle. Only talk to your immedate friends.
Interface Segregation Principle: Clients should not be forced to depend upon interfaces that they don't use. The dependency of one class to another one should depend on the smallest possible interface.
Dependence Inversion Principle: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.
Single Responsibility Principle: There should never be more than one reason for a class to change.
Open Closed Principle: Software entities like classes, modules and functions should be open for extension but closed for modifications.
Liskov Substitution Principle: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
Law of Demeter: Least Knowledge Principle. Only talk to your immedate friends.
Interface Segregation Principle: Clients should not be forced to depend upon interfaces that they don't use. The dependency of one class to another one should depend on the smallest possible interface.
Dependence Inversion Principle: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.
本文探讨了在使用动态规划(DP)时如何遵循面向对象编程(OO)的原则,以确保代码的可扩展性和维护性。通过遵循单一职责原则、开放封闭原则、里氏替换原则、依赖倒置原则、接口隔离原则和迪米特法则,开发者可以有效地避免代码混乱,并实现高效、可维护的解决方案。

被折叠的 条评论
为什么被折叠?



