Facade Design pattern and Abstraction

what is the difference between facade design and abstraction in java? i simply feel that it is as simple as interface in java and serve the same purpose.

I saw more about people saying that it is a first contact for client, hiding more interfaces and classes. but all the above are also the purpose of interfaces.!!!

Confused here!!!!!!. Please give a small example and help me around.

thanks, Punith

Answer:1

From Wikipedia:

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.

This means that the facade is an actual object with behavior, not an interface. Whereas the role of an interface is to specify what operations must be supported by an implementation, the facade provides easy/convenient ways to use a body of code (e.g. a whole library), by for example providing commonly used setup, default values, etc.

Answer:2

The Facade Pattern is a design pattern. All design patterns are abstractions. The real question here is "What is an abstraction?".

An abstraction is when you hide some details. For example, you might have an app with with a service for each domain model (e.g. User, Item, Action, whatever). You'd like the consumer of your API to not have to know that detail (i.e. worry about getting the correct services, how to use them together, etc), so you put up a "facade", which is simply a service that does everything all those other services do, but in one interface. That's an abstraction, because the Facade user doesn't know that there are N services under the covers, nor does he/she care how they are used, because he/she just uses the unified implementation.

You've abstracted the details away, using a design pattern.

Answer:3

I have a List, and I want to loop through that List and remove some record base on some condition. Here is what I do public void foo(List<Bar> recordList){ for(Bar bar : recordList){ ...

I have a class that extends Application, called MyApplicaton, that I use to store global variables, i.e., variables I want to be able to access anywhere throughout my android app. In activites, I get ...

We have a web application that allows users to upload photos which will then be displayed in a specified page after upload. The upload module places the images inside the exploded war directory, e.g. ...

I`m just wondering.... If it was the case that I was thinking in creating different reseases for each custumer that I sold my software, could I check each one with MD5 just changing a comment inside ...