java中的门面设计和抽象有什么区别? 我只是觉得它和java中的接口(interface)一样简单,而且用途相同。
看到比较多的人说是client的第一次接触,隐藏了更多的接口(interface)和类。但以上所有也是接口(interface)的目的。!!!
在这里很困惑!!!!!!请举一个小例子并帮助我。
谢谢, 惩罚
最佳答案
来自维基百科:
A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:
make a software library easier to use, understand and test, since the facade has convenient methods for common tasks;
make the library more readable, for the same reason; reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system;
wrap a poorly-designed collection of APIs with a single well-designed API (as per task needs).
An adapter is used when the wrapper must respect a particular interface and must support a polymorphic behavior. On the other hand, a facade is used when one wants an easier or simpler interface to work with.
这意味着外观是具有行为的实际对象,而不是接口(interface)。接口(interface)的作用是指定实现必须支持哪些操作,而外观提供了使用代码主体(例如整个库)的简单/方便的方法,例如提供常用的设置、默认值等.
关于java - 外观设计模式和抽象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10913773/