开发者社区 问答 正文

SOLID包含哪些设计原则?

SOLID包含哪些设计原则?

展开
收起
罗鹏大佬 2022-04-18 17:36:11 496 分享 版权
来自: 阿里技术
1 条回答
写回答
取消 提交回答
  • 1、单一职责原则:A class should have one, and only one, reason to change,一个类只能因为一个理由被修改。 2、开闭原则:Entities should be open for extension, but closed for modification,对扩展开放,对修改关闭。 3、里氏替换原则:Functions that use pointers of references to base classes must be able to use objects of derived classes without knowing it,子类可以替换父类。 4、接口隔离原则:A client should not be forced to implement an interface that it doesn’t use,不能强制客户端实现它不使用的接口,应该把接口拆的尽可能小。 5、依赖倒置原则:Abstractions should not depend on details. Details should depend on abstractions,抽象不依赖于细节,而细节依赖于抽象。

    2022-04-19 15:52:17
    赞同 展开评论
问答地址: