What is the difference between an Abstraction and a Facade?

风格不统一 提交于 2019-12-07 06:44:31

问题


What is the difference between an 'Abstraction' and a 'Facade'?

Is there a difference at all? Or are the terms interchangeable?


回答1:


The facade pattern is an simplified interface to a larger, possibly more complex code base. The code base may be a single class, or more. The facade just gives you a simple interface to it.

Abstraction, is used to represent a concept, but not to be bound to any specific instance. (Ie: An abstract class). This doesn't imply simplifying (like the facade pattern does), but rather making a 'common' interface or representation.




回答2:


Facade is a specific design pattern, meant to hide the internal stuff inside a package / module from its clients behind a well-defined interface. It usually hides several interfaces/classes behind a single common one, hence its name.

'Abstraction' is a general term, meaning to hide the concrete details of something from the outside world.

So these two are not interchangeable terms.




回答3:


Facade is a GoF design pattern, very specific. In essense, it's about hiding over-complex functionality from the main body of your application.

Abstraction is a more vague term related to hiding functionality of a service from its client.




回答4:


Abstract to me means taking the common parts of a collection of things and creating a base thing from them, which the collection can then draw on, sort of like a parent class.

A façade is a face (literally speaking), so they analogy of a base class doesn't quite hold. A façade is more of an interface, so it wouldn't have to be related to the things that use it. I think of it more like a mask. My class will have a "disposable" mask, for example.

So the difference, in my mind, is that an abstract pattern allows a hierarchy to be built, where as a façade pattern allows classes look similar.



来源:https://stackoverflow.com/questions/2288643/what-is-the-difference-between-an-abstraction-and-a-facade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!