Facade Design Pattern

The facade design pattern allows us, to provide a simplified interface from multiple class libraries. It provides a simple interface that hides the complexity of the class libraries being used.

UML Class diagram
For example, if the client code needs to access three different class libraries for a single functionality, instead of having the client code accessing those 3 class libraries, we can just create another class, that calls the required class libraries and have the client access only the class that you have created. The result is a simplified interface for the client and the client will not need to know the details of the actual (three) class libraries.

Real World Examples for Facade Pattern A MortgageApplication object, which provides a simplified interface to a large subsystem of classes measuring the credit worthiness of an applicant.

Implementation of above example in C#.Net
Create Customer class,
public class Customer
{
    private string _name;
        
    public Customer(string name)
    {
        _name = name;
    }
        
    public string Name
    {
        get { return _name; }
    }
}

Create subsystem1 (Library1 from class diagram),
namespace DesignPatterns.Library1
{
    public class Credit
    {
        public bool HasGoodCredit(Customer c)
        {
            Console.WriteLine("Check credit for " + c.Name);
            return true;
        }
    }
}

Create subsystem2 (Library2 from class diagram),
namespace DesignPatterns.Library2
{
    public class Bank
    {
        public bool HasSufficientSavings(Customer c, int amount)
        {
            Console.WriteLine("Check bank for " + c.Name);
            return true;
        }
    }
}

Create subsystem3 (Library3 from class diagram),
namespace DesignPatterns.Library3
{
    public class Loan
    {
        public bool HasBadLoans(Customer c)
        {
            Console.WriteLine("Check bad loans for " + c.Name);
            return false;
        }
    }
}

Now, create a Façade class,
namespace DesignPatterns.Facade
{
    public class Mortgage
    {
        private Bank _bank = new Bank();
        private Loan _loan = new Loan();
        private Credit _credit = new Credit();

        public bool IsEligible(Customer cust, int amount)
        {
            Console.WriteLine("{0} applies for {1:C} loan\n", cust.Name, amount);
            bool isEligible = true;

            // Check creditworthyness of applicant
            if (!_bank.HasSufficientSavings(cust, amount))
                isEligible = false;
            else if (_loan.HasBadLoans(cust))
                isEligible = false;
            else if (!_credit.HasGoodCredit(cust))
                isEligible = false;

            return isEligible;
        }
    }
}

Create a client to use above implemented façade class (Mortgage),
private void btnFacade_Click(object sender, EventArgs e)
{
    // Facade class
    Mortgage mortgage = new Mortgage();

    // Evaluate mortgage eligibility of customer
    Customer customer = new Customer("test customer");
    bool eligible = mortgage.IsEligible(customer, 2000000);

    Console.WriteLine("\n'" + customer.Name + "' has been " + (eligible ? "Approved" : "Rejected"));
}

Output
test customer applies for $2,000,000.00 loan
Check bank for test customer
Check bad loans for test customer
Check credit for test customer

 'test customer' has been Approved

Common mistakes while implementing facade pattern
In my experience the common mistakes I have seen are,
  • Just for the sake of introducing a facade layer developers tend to create additional classes. Layered architecture is good, but assesses the need for every layer.
  • Methods in facade layer have only one or two lines which calls the other components. If facade is going to be so simple, it invalidates its purpose and clients can directly do that by themselves.
  • A controller is not a facade.
  • Facade is ‘not’ a layer that imposes security and hides important data and implementation.
  • Don’t create a facade layer in advance. If you feel that in future the subsystem is going to evolve and become complicated to defend that do not create a stub class and name it a facade. After the subsystem has become complex you can implement the facade design pattern. 
  • Subsystems are not aware of facade and there should be no reference for facade in subsystems. 
Summary of Facade Design Pattern
  • Makes a software library easier to use, understand and test, since the facade has convenient methods for common tasks
  • Makes code that uses 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.

Comments

  1. Hadoop training in chennai1/20/2015

    hi,very nice article.i have to learned for lot of information...hadoop training in chennai

    ReplyDelete
  2. Your blog is really useful for me. Thanks for sharing this informative blog. If anyone wants to get real time Oracle Training in Chennai reach FITA located at Chennai. They give professional and job oriented training for all students.

    ReplyDelete
  3. Excellent post!!! The future of .net application development is on positive note. It offers huge career prospects for talented professionals all over the world. Training on .net technology will ensure good salary package. .Net Course in Chennai

    ReplyDelete
  4. Thank you so much for sharing this wonderful information, I find your content to be unique and genuine. Keep sharing article and this will help many in finding the best institute for Hadoop Training Chennai

    ReplyDelete
  5. Hi, nice article, nice example for private, public class related Php training in chennai

    ReplyDelete
  6. Nice information about the faced design pattern.Its very awesome..Thanks..Its very useful..
    Selenium Training in Chennai | QTP Training in Chennai | Software Testing Training in Chennai | QTP Training in Chennai

    ReplyDelete
  7. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.

    Regards..
    Software Testing Training Institutes in Chennai

    ReplyDelete
  8. Anonymous6/24/2015

    Thanks for sharing this information. Salesforce is a cloud based CRM. Nowadays most of the multinational companies used this CRM for managing their customers. To know more details call 9841746595.

    Regards..
    Salesforce Training in Chennai

    ReplyDelete
  9. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    Regards,
    sas training in Chennai|sas course in Chennai|sas training institute in Chennai

    ReplyDelete
  10. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Regards,
    Informatica training in chennai|Informatica courses in Chennai|Informatica institutes in Chennai

    ReplyDelete
  11. Thanks for sharing this information in here. As a fresher any one can also go for the below training programs.
    Java Training
    .Net Training
    PHP Training

    ReplyDelete
  12. How good is it to do an Android Training in Chennai? Can someone suggest?

    ReplyDelete
  13. Thanks for sharing your informative article on Hive ODBC Driver. Your article is very descriptive and assists me to learn whole concept in detail. Hadoop Training in Chennai | Big Data Training in Chennai

    ReplyDelete
  14. Thanks for sharing this niche useful informative post to our knowledge, Actually SAP is ERP software that can be used in many companies for their day to day business activities it has great scope in future.
    Regards,
    SAP training in chennai|SAP courses in chennai|SAP institutes in chennai|SAP Course in Chennai

    ReplyDelete

  15. if you are looking for the Big Data Training in indore i would highly recommened you the ssi , they are the one the best education institute in indore

    ReplyDelete
  16. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Regards,
    Python Training in Chennai|Python Courses in Chennai

    ReplyDelete
  17. Website are the only way to execute a company's projects to their visitors. And it is mandatory to maintain a responsive one as well. Your content explicitly states that. Thanks for sharing this worth able article here. Keep up this good work.

    Web designing course in chennai | Web design course | Web design training in chennai

    ReplyDelete
  18. Maharashtra Police Wireless HC ASI Recruitment 2016


    knowledge from your web site.it's a reputable great report.......

    ReplyDelete
  19. UP Urdu Teacher Recruitment 2016

    I Like your site because you have a good post on this blog....

    ReplyDelete
  20. Learning new technolgoy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.

    JAVA Training in Chennai | Mobile application testing training in Chennai | Hadoop course in chennai

    ReplyDelete
  21. Using big data analytics may give the companies many fruitful results, the findings can be implemented in their business decisions so as to minimize their risk and to cut the costs.
    hadoop training in chennai|big data training|big data training in chennai

    ReplyDelete
  22. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing.
    Fita Chennai reviews
    Hadoop Training in Chennai
    Big Data Training in Chennai

    ReplyDelete
  23. This facade design pattern is very useful including the architecture is amazing.It is fully explained in programming way.Thanks for this.
    Java Training in Chennai

    ReplyDelete
  24. Thanks for posting this information in this blog. .net programming concept is clearly explained. The facade design architecture helps in understanding the concept in a clear manner Loadrunner Testing Training in Chennai

    ReplyDelete
  25. Nice..It's more informative about facade design. It provides a simple interface that hides the complexity of the class libraries being used.All the programs are solved easily..Update more blogs like this.
    Android Training in Chennai

    ReplyDelete
  26. Anonymous3/07/2016

    This blog explains Facade Design Pattern is a method that provide simplified interface from multiple class libraries. This hides the very large information and provide minimum information. All the methods of this blog explain clearly. Thank you very much for this blog.

    Informatica Training in Chennai

    ReplyDelete
  27. Anonymous3/07/2016

    thanks for sharing this kind of valuable information.
    about this .net course which is useful and unforgetable article.
    CCNA Training in Chennai

    ReplyDelete
  28. I am learning now only facade design pattern , it is really nice and unique and it tells about the merits and demerits of this pattern it will be useful for me.


    dot net training in chennai

    ReplyDelete
  29. well said about UML class diagram with its code. clearly understood about your concepts. keep update.
    Loadrunner Training in Chennai

    ReplyDelete
  30. You have clearly explained about facade design pattern..its more useful and informative to know about this design..Keep in blogging like this ..
    Linux training in chennai

    ReplyDelete
  31. this blog clearly explains the concept of facade pattern and design. It is explained by simple interface with complex libraries. Coding helps in understanding the concept in a clear manner
    ssis training in chennai

    ReplyDelete
  32. Very happy to see this blog. Gives a wonderful information with coded explanaion. Thank you for this blog. very useful to me.
    Informatica Training in Chennai

    ReplyDelete
  33. This facade design pattern is awesome.It is to read and is easy to understanding format.
    Sharepoint developer training in chennai

    ReplyDelete
  34. Great... Excellent sharing.. This is very helpful for beginers. Read that provide me more enthusiastic. This helps me get a more knowledge about this topic. Thanks for this.
    Dotnet Training in Chennai

    ReplyDelete
  35. It is the best article to read this information.good topic to discuss this article.I am very enjoy to read this information.It is to get the inspiration for me to go to the next level.

    android training in chennai

    ReplyDelete
  36. This blog is really informative. I gained more knowledge by reading your post. Thanks for providing us the useful information with us. Your blog is really helpful for me in attaining my knowledge in a right way.

    Selenium Training in Chennai

    ReplyDelete
  37. Great blog..You have clearly explained how to install hadoop ..Step by step explanation is too good to understand..Its very useful for me to understand..Keep on sharing..
    SAS training in chennai

    ReplyDelete
  38. Great blog..You have clearly explained about the concept..Step by step explanation is too good to understand..Its very useful for me to understand..Keep on sharing..
    Web designing training in chennai

    ReplyDelete
  39. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.


    SAP training in Chennai

    ReplyDelete
  40. This blog is impressive and informative.It clearly explains about the concept and its techniques.Thanks for sharing this information.Please update this type of information
    sas Training in Chennai

    ReplyDelete
  41. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up.

    SEO training in Adyar

    ReplyDelete
  42. Informatica is one of the most trusted and effective ETL software which is known globally. Informatica is one data warehousing ETL tool. Informatica ha very go opportuities for job across the world.
    informatica training in chennai | informatica training institute in Chennai | informatica classes in Chennai

    ReplyDelete
  43. Big data is used extensively in MNC today as using big data leads to accurate decision making and there are is a huge demand for the big data analysts.
    Big data training in Chennai | Hadoop training in Chennai | Big data training institute in Chennai

    ReplyDelete
  44. Anonymous5/21/2016

    thanks for sharing about dotnet..
    SEO training in hyderabad by experts in digital markeing And by prosessional experts in seo.All the training by placement and also guide by the professionals.SEO training in hyderabad

    ReplyDelete
  45. To keep ourselves up to date with the current trend is not an easy task in IT. But we can, through quality and worth able content like this. Thanks for sharing this web page. Please write more articles like this in future.
    PHP training in Chennai | PHP course in Chennai

    ReplyDelete
  46. Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    SAS Training in Chennai | SAS Course in Chennai

    ReplyDelete
  47. nice posts..The strategy you have poted is excellent thank for sharing../
    SAS Institute introduced the SAS Certified Professional Program,training proper understanding of how the SAS software works. Among the five certification programs that SAS Institute has come up with, SAS training can be considered as the entry point into the big data and the data analytics industry.
    SAS online training in hyderabad

    ReplyDelete
  48. facade design pattern nice posts..

    Hadoop training in hyderabad.All the basic and get the full knowledge of hadoop.
    hadoop training in hyderabad

    ReplyDelete
  49. Thanks for sharing such these examples on Dot net. This is really useful and continue sharing more about Dot net.
    Regards,
    DOTNET Training in Chennai | DOTNET course in Chennai | DOTNET Training Institute in Chennai

    ReplyDelete
  50. Thanks for sharing your ideas on mobile application.Really useful to me.Continue sharing more like this.
    Regards,
    Mobile Application Training in Chennai | Mobile Apps Testing Training | Mobile Application Testing Training

    ReplyDelete
  51. Thanks for sharing information to our knowledge, it helps me plenty keep sharing…
    Java Training in Chennai | JAVA Course in Chennai

    ReplyDelete
  52. Hello Admin,
    Awesome Post! I like writing style, how you describing the topics throughout the post. I hope many web reader will keep reading your post at the end, Thanks for sharing your view.
    Regards,
    DOT NET Training Institutes in Chennai|Best DOT NET Training in Chennai|dot net training institutes in chennai

    ReplyDelete
  53. Excellent post!!! Java is most popular and efficient programming language available in the market today. It helps developers to create stunning desktop/web applications loaded with stunning functionalities.Best Angularjs Training in Chennai
    AngularJS Training in Chennai

    ReplyDelete
  54. Thank you for Sharing. We are the best erp software providers in chennai. For more details call +91 9677025199 or email us on info@bravetechnologies.in
    erp in chennai

    ReplyDelete
  55. The best thing is that your blog really informative thanks for your great information!
    erp providers in chennai

    ReplyDelete
  56. Greate pieces. Keep writing such kind of information regarding etl testing vacancies in hyderabad. Im really impressed by your post.

    ReplyDelete





  57. HELLO GUYS SEARCHING FOR BEST DIGITAL MARKETING SEO TRAINING IN INDORE THAN YOU COME TO THE RIGHT WHERE YOU GOT THE BEST DIGITAL MARKETING INSTITUTION HERE IN INDORE.

    digital marketing training indore

    ReplyDelete
  58. hi, i really enjoyed to read your article... thanks for sharing your valuable information and ideas... it is very helpful to me....

    Dot Net Training in chennai | Dot Net Training institute in chennai

    ReplyDelete
  59. Interesting and informative article.. very useful to me.. thanks for sharing your wonderful ideas.. please keep on updating..
    Web Designing Training Institute in Chennai | Web Designing Training Institute in Velachery.

    ReplyDelete

Post a Comment

Popular posts from this blog

Auto Scroll in Common Controls

Convert typed library (.tlb) to .net assembly?