开放/封闭原则背后的含义和理由是什么? [英] What is the meaning and reasoning behind the Open/Closed Principle?

查看:99
本文介绍了开放/封闭原则背后的含义和理由是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开放式/封闭式原则指出,软件实体(类,模块等)应打开以进行扩展,但应关闭以进行修改.这是什么意思,为什么它是良好的面向对象设计的重要原则?

The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is it an important principle of good object-oriented design?

推荐答案

具体来说,这是有关OOP中设计的圣杯",即使实体具有足够的可扩展性(通过其单独的设计或通过其参与体系结构)无需重新编写代码即可支持将来无法预料的更改(有时甚至无需重新编译**).

Specifically, it is about a "Holy Grail" of design in OOP of making an entity extensible enough (through its individual design or through its participation in the architecture) to support future unforseen changes without rewriting its code (and sometimes even without re-compiling **).

做到这一点的一些方法包括多态性/继承,组成,控制反转(aka DIP),面向方面的编程,诸如策略的模式,访问者,模板方法以及OOAD的许多其他原理,模式和技术.

Some ways to do this include Polymorphism/Inheritance, Composition, Inversion of Control (a.k.a. DIP), Aspect-Oriented Programming, Patterns such as Strategy, Visitor, Template Method, and many other principles, patterns, and techniques of OOAD.

**请参见6个打包原则", REP,CCP,CRP,ADP,SDP, SAP

** See the 6 "package principles", REP, CCP, CRP, ADP, SDP, SAP

这篇关于开放/封闭原则背后的含义和理由是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆