外墙是否利用开放原则? [英] Does Façade leverage the Open-Closed Principle?

查看:165
本文介绍了外墙是否利用开放原则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开放式的维基百科页面(截至今天2013-02-27)封闭原则说,它是通过继承实现的。

The Wikipedia page (as of today 2013-02-27) for the Open-Closed Principle says that it's realized via inheritance.


打开/关闭原则的名称有两种使用方式。两种方式都使用继承来解决明显的困境,但目标,技术和结果是不同的。

两种方式是指Meyer的实现继承和更常见的多态扩展。

The "two ways" refers to Meyer's implementation inheritance and the more common Polymorphic extensions.

无论如何,我的问题是关于外墙模式,其中使用继承。由于它以简单的界面定义了一个更复杂的子系统(或库)的抽象,这不能被视为开放原则吗?更具体地说:

Anyway, my question is about the Façade pattern, which does not use inheritance. Since it defines an abstraction in the form of a simplified interface to a more complex sub-system (or library), can't this be seen also as the Open-Closed Principle? More specifically:


将子系统(或库)扩展开放到使用Façade,其界面被关闭以修改

或者我只是伸展信息隐藏的边界这非常接近OCP,特别是如果您将其视为受保护的变体)。

Or am I just stretching the boundaries of information hiding (which is very close to OCP, especially if you consider it as Protected Variations).

推荐答案

不,Facade模式解决了与OCP不同的问题。门面只是一个类,面向其他类。门面使其客户不受其所面临的课程的变化,但这不是OCP。 OCP是关于个别课程如何根据需求的变化而改变的。没有关于立面的任何内容都被设置为引导这些更改。如果客户对Facade的要求发生变化,Facade也会如此。如果门面正面改变的任何课程都会改变,那么门面就是这样。

No, the Facade pattern addresses a different concern than the OCP. A Facade is just a class that fronts for some other classes. The Facade insulates its clients from changes in the classes it fronts for, but that's not the OCP. The OCP is about how individual classes change in response to changes in requirements. Nothing about a Facade is set up to channel those changes. If the client's requirements on the Facade change, so will the Facade. If any of the classes that the Facade fronts for change in ways that the Facade cares about, so will the Facade.

可以想象一下,设置的Facade版本遵循OCP - 也许是一个Facade,其客户端的接口是接口或抽象类,它被关闭以进行修改,但可以扩展到适应新的要求 - 实际上我一直以这种方式实现Facade,但这不是经典的门面描述。

One can imagine a version of Facade that is set up to follow the OCP — perhaps a Facade whose interface to the client is an interface or abstract class which is closed for modification but can be extended to accomodate new requirements — and in fact I've always implemented Facades that way, but that's not part of the classic description of Facade.

这篇关于外墙是否利用开放原则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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