In this article I would like to explore the Facade design pattern. The actual
pronunciation is fu'saad. The dictionary meaning of the word Façade is "A showy
misrepresentation intended to conceal something unpleasant"
Now let us enter the challenge.
Challenge
You are working on a database application. Frequently you need to execute UPDATE
and DELETE SQL queries. Each time there is a need to create the SqlConnection
and SqlCommand class, assign the connection to command and execute the query.
The series of activities looks like:
SqlConnection
connection = new
SqlConnection("connection string" );
SqlCommand command =
new SqlCommand();
command.Connection = connection;
command.CommandText = "UPDATE Customer SET
Processed=1";
command.ExecuteNonQuery();
You need to repeat the same code wherever execute queries are required. How to
make this code better?
Definition
"Provide a unified interface to a set of interfaces in a system. Facade defines
a higher-level interface that makes the subsystem easier to use."
Implementation
Using Façade, we can improve the situation. We can find only the query is
different in each case – the parameters like connection string is common for the
entire application.
SQLFacade.ExecuteSQL("UPDATE
query here..");
After using the Façade the code will look like above.
The complicated code is being pulled to the background SQLFacade class.
namespace
FacadePattern
{
public class
SQLFacade
{
public static
bool ExecuteSQL(string
sql)
{
SqlConnection connection =
new SqlConnection("connection
string");
SqlCommand command =
new SqlCommand();
command.Connection = connection;
command.CommandText = sql;
command.ExecuteNonQuery();
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.


Sujit BhujbalPosted Jan 4, 2012, 11:42 PM
Hi Very nice and simple article on FACADE design pattern Regards Sujeet
Vineet Kumar SainiPosted Dec 27, 2011, 12:06 PM
Good work....
Akash AhlawatPosted Dec 27, 2011, 12:03 PM
Really complicated topic to explain
Arjun PanwarPosted Dec 27, 2011, 11:53 AM
Thanks Jean
Manish SinghPosted Dec 27, 2011, 11:50 AM
Really good work
Stephen JohnsonPosted Dec 26, 2011, 11:45 PM
Its a Unique concept. I will surely try to implement this.
Abhi KumarPosted Dec 26, 2011, 11:20 PM
Nice article.
Vikas MishraPosted Dec 26, 2011, 4:17 PM
Hi Jean you have done a very good work......... thanks for sharing