java - 外观设计模式和抽象

标签 java oop design-patterns

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/

相关文章:

java - Collection可以用作Hashmap java中的键吗?

php - 将设计模式应用于特定行为

java - java中字符流有什么用?

java - 自定义nifi处理器-流文件的写入

c++ - 这些c++语法等同于什么?

iphone - Objective C 初始化方法和继承

java - Java 的数据库迁移模式?

javascript - 如何将用户输入的换行符从文本区域保存到电子邮件内容

java - 如何在 JPanel 中垂直居中对齐 JScrollPane?

c# - 接口(interface)如何模拟多重继承?