java 外观模式和抽象工厂模式有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11188869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the differences between facade pattern and abstarct factory pattern?
提问by Adalarasan Sachithanantham
I'm not asking the interview point of view. I want to know the real time scenario of implemented in the projects like the struts framework etc.
我不是在问面试的观点。我想知道在struts框架等项目中实现的实时场景。
采纳答案by Sumit Singh
The facade pattern is used when you want to hide an implementationor it is about changing interface of some class or set of classes. Builder hides the process of construction by decomposing it in smaller steps.
当你想隐藏一个实现或者它是关于改变某个类或一组类的接口时,可以使用外观模式。Builder 通过以更小的步骤分解来隐藏构建过程。
Abstract factory pattern is used when you want to hide the details on constructing instances.
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
当您想隐藏构建实例的细节时,使用抽象工厂模式。
提供用于创建相关或依赖对象系列的接口,而无需指定它们的具体类。
回答by Yair Zaslavsky
Dunno why this was voted negatively. this is a legitimate question.
不知道为什么这被否决了。这是一个合理的问题。
My take - A facade is a class or a group of classes hiding internal implementation/services from the user.
我的看法 - 外观是一个类或一组向用户隐藏内部实现/服务的类。
An abstract factory encapsulates a group of factories which are used for creating objects, whereas Facade can be used to provide abstraction to all kinds of operations, not just creation
抽象工厂封装了一组用于创建对象的工厂,而 Facade 可以用于为各种操作提供抽象,而不仅仅是创建
回答by Hyman
They are two patterns used for thing thats that are completely unrelated.
它们是用于完全不相关的事物的两种模式。
With the Abstract Factory Patternyou just provide a common factory builder for many different builders for the same thing. This can be used whenever you need to provide an interface to a set of builders meant to be used with something in common (the product) without bothering on what are you going to build or which factory are you going to use.
使用抽象工厂模式,您只需为同一事物的许多不同构建器提供一个通用工厂构建器。当您需要为一组构建器提供接口时,可以使用它来与一些共同的东西(产品)一起使用,而不必担心您要构建什么或要使用哪个工厂。
The Facadepattern instead is used to provide a simple interface to a lot of different operations that the client classes should not see.
相反,外观模式用于为客户端类不应该看到的许多不同操作提供一个简单的接口。