Quick revision
The short answer
A facade is a class that offers one simple interface over a complex subsystem, so callers do one thing with one call instead of coordinating many classes. It differs from an adapter in intent: an adapter converts an existing interface into the one a client expects, usually for one class, while a facade simplifies, usually over many classes. JdbcTemplate is a facade over JDBC connections, statements, result sets and exception handling, SLF4J is a facade over logging implementations, and an application service that coordinates several domain objects for one use case also acts as a facade.
What to remember
In this answer, we saw that a facade gives a simple interface over a complex subsystem, while an adapter converts an interface into one a client expects, usually for a single class. JdbcTemplate is a facade over JDBC connections, statements, result sets and exception translation, SLF4J is a facade over logging implementations, and an application service that coordinates several domain objects for one use case acts as a facade too, as long as it stays focused.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A facade is a class that offers one simple interface over a complex subsystem, so callers do one thing with one call instead of coordinating many classes. It differs from an adapter in intent: an adapter converts an existing interface into the one a client expects, usually for one class, while a facade simplifies, usually over many classes. JdbcTemplate is a facade over JDBC connections, statements, result sets and exception handling, SLF4J is a facade over logging implementations, and an application service that coordinates several domain objects for one use case also acts as a facade.
Why this question is asked
Facades are everywhere in Java, often without the name: most of what makes Spring pleasant to use is a facade over a verbose lower-level API. Interviewers ask about the facade together with the adapter because the two look alike in code, a class that wraps other classes, and telling them apart shows that we think about the purpose of a pattern, not just its shape. In this answer, we will recap what a facade is, see JdbcTemplate replace raw JDBC, look at SLF4J, compare facade and adapter directly, and then see the facade in our own application services.
1A Quick Recap of the Facade Idea
A subsystem is a group of classes that together do a job, such as talking to a database or sending mail. Using a subsystem directly often means knowing many classes, calling them in the right order and cleaning up correctly. A facade is a single entry point that does the common tasks for us: it knows the subsystem's details so the caller does not have to.
The name comes from buildings: the facade is the front we see, hiding the structure behind it. Importantly, the subsystem is still there. A facade does not usually forbid direct use of the classes behind it; it just makes the common path short.
2JdbcTemplate: a Facade Over JDBC
Raw JDBC, the standard Java API for relational databases, needs several objects for one query: a Connection, a PreparedStatement and a ResultSet, each of which must be closed, plus handling of the checked SQLException.
- Repository codeone call:
queryForList(sql, type, args) - JdbcTemplate facadegets connection, binds parameters, maps rows, closes, translates errors
- JDBC subsystem
DataSource, Connection,PreparedStatement,ResultSet, SQLException - JDBC driver and databasePostgreSQL, MySQL and others
4 layers, from the top down. Step through them one at a time.
Notice what the facade took over: getting the connection, ideally the one bound to the current Spring transaction, creating and closing the statement and result set, mapping rows, and translating SQLException into Spring's DataAccessException hierarchy, such as DuplicateKeyException, which is unchecked and tells us what went wrong. JdbcTemplate does not hide JDBC completely; through callbacks such as RowMapper or ConnectionCallback we can still reach it when we need to.
3SLF4J: a Facade Over Logging
SLF4J, the Simple Logging Facade for Java, has the facade in its name. Application and library code logs through the small SLF4J API, Logger and LoggerFactory, and at run time SLF4J sends the calls to whichever logging implementation is present, such as Logback or Log4j 2.
The benefit is especially large for libraries: a library that logs through SLF4J does not force a logging framework on its users. The {} placeholders also show the facade simplifying: the message is only formatted if the level is enabled, so we do not need an isEnabled check around each call. SLF4J also has adapter parts, bridges that take calls from other logging APIs and route them into SLF4J, which shows that one library can contain both patterns.
4Facade Compared With Adapter
Both patterns wrap something, so the difference is intent. An adapter exists because an interface does not fit: the client already expects a specific interface, and the adapter makes an existing class match it, without making anything simpler. InputStreamReader makes a byte stream look like a Reader. A facade exists because an interface is too complex: there is no prescribed interface the client expects; we design a new, smaller one around the tasks callers have, and it usually covers several classes.
| Question | Adapter | Facade |
|---|---|---|
| Why it exists | An interface does not fit | A subsystem is too complex |
| Interface it offers | One the client already expects | A new, simpler one |
| Wraps | Usually one class | Usually many classes |
| Simplifies? | Not necessarily | Yes, that is the point |
| Java examples | Arrays.asList, InputStreamReader | JdbcTemplate, SLF4J API |
5Application Services as Facades
The pattern also appears in our own code. An application service, for example CheckoutService with a method placeOrder(cart, payment), coordinates several domain objects and infrastructure pieces for one use case: it checks stock, prices the cart, takes the payment, saves the order and publishes an event. The controller calls one method and does not need to know the order of those steps.
That is a facade over the domain for one use case, and it is healthy as long as it stays focused. The risk, which a later question in this topic explores, is a facade that collects every operation of an area and grows into a god class with dozens of methods. A facade should stay a thin coordinator; the real rules belong in the domain objects behind it.
6Follow-up questions
Does a facade stop callers from using the subsystem directly?
Usually not, and it should not try too hard. The facade covers the common cases. Callers with special needs can still use the classes behind it, as JdbcTemplate allows through callbacks. Forbidding that tends to produce facades with dozens of rarely used methods.
Is a Spring Boot starter a facade?
In a sense, yes. A starter and its auto-configuration give a simple entry point, a dependency and a few properties, over a complex setup of many beans. It is closer to a facade over configuration than over run-time calls.
Can a facade become a problem?
Yes, when it grows without limits. A facade that every caller depends on and that gathers unrelated operations becomes a bottleneck for changes and a source of merge conflicts. Splitting it by use case keeps each facade small.
7Conclusion
In this answer, we saw that a facade gives a simple interface over a complex subsystem, while an adapter converts an interface into one a client expects, usually for a single class. JdbcTemplate is a facade over JDBC connections, statements, result sets and exception translation, SLF4J is a facade over logging implementations, and an application service that coordinates several domain objects for one use case acts as a facade too, as long as it stays focused.
Open with
A facade is a class that gives a simple interface over a complex subsystem, so callers make one call for a common task instead of coordinating many classes themselves.
Then, if they want more
The difference from an adapter is intent. An adapter exists because an interface doesn't fit: the client already expects a particular interface and the adapter converts an existing class to it, like InputStreamReader turning bytes into a Reader, and it doesn't necessarily simplify anything.
A facade exists because something is too complicated, so we design a new, smaller interface, usually over many classes. The classic Java example is JdbcTemplate: with raw JDBC I have to get a connection, prepare a statement, bind parameters, iterate a result set, close everything and handle SQLException.
JdbcTemplate does all of that in one call, uses the transaction's connection, and translates SQLException into Spring's unchecked DataAccessException hierarchy, while still letting me drop down to JDBC through callbacks. SLF4J is another, it's even in the name: code logs through its small API and it delegates to Logback or Log4j 2 at runtime, which is great for libraries.
And in our own code, an application service like a checkout service that coordinates stock, pricing, payment and persistence for one use case is a facade, as long as it stays focused on that use case.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the facade pattern, and how does it differ from adapter? Give Java examples.": https://scrivio-interview-library.netlify.app/java/structural-patterns/87ba865b87/