Jul 14, 2013

Facade Design Pattern

89 comments
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.

89 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 posts is really helpful for me.Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.If anyone wants to get Dot Net Training in Chennai reach FITA, rated as No.1 Dot Net Training Institutes in Chennai.





    ReplyDelete
  3. 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
  4. Awesome Blogs share more information and refer the link Android Training in Chennai

    ReplyDelete
  5. Android Training in Chennai2/23/2015

    Awesome Blogs share more information and refer the link Android Training in Chennai

    ReplyDelete
  6. 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
  7. 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
  8. I have joined the oracle Trained in Training in Bangalore. Oracle Trainer will be teaching in practically Manner. So I can Easily able to understand the any Concept. This is very helpful for the interviews Purpose . I would refer my frnds to joined this institute. Visit Us, Oracle Training Bangalore

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

    ReplyDelete
  10. 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
  11. Your blog is really useful for me. Thanks for sharing this useful blog..Suppose if anyone interested to learn Android Course in Chennai please visit fita academy which offers best Android Training in Chennai at reasonable cost.

    ReplyDelete
  12. 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
  13. 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
  14. 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
  15. 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
  16. Wow, brilliant article that I was searching for. Helps me a lot in taking class for my students, so using it in my work. Thanks a ton. Keep writing, would love to follow your posts.
    Shashaa
    Dot Net training in Chennai | Dot Net training in Chennai | Dot Net training in Chennai

    ReplyDelete
  17. 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
  18. How good is it to do an Android Training in Chennai? Can someone suggest?

    ReplyDelete
  19. 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
  20. 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
  21. This is exactly what I was searching for. Awesome post. Thanks a bunch. Helped me in taking class for my students. Wish to follow your posts, keep writing! God Bless!
    Shashaa
    Dot Net course in Chennai | Dot Net course in Chennai | Dot Net course in Chennai

    ReplyDelete

  22. 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
  23. It’s too informative blog and I am getting conglomerations of info’s. Thanks for sharing; I would like to see your updates regularly so keep blogging. If anyone looking ccna just get here
    Regards,
    ccna course in Chennai|ccna training in Chennai|ccna training institute in Chennai

    ReplyDelete
  24. 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. Best DOT NET Training institute in Chennai | DOT NET Training Institutes in Chennai

    ReplyDelete
  25. 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
  26. Hello admin, thank you for your informative post on hadoop training in Chennai. It helped a lot in training my students during our hadoop training Chennai sessions. We at Fita, provide big data training in Chennai for students who are interested in choosing a career in big data.

    ReplyDelete
  27. TechnoSoftwar proficient in web design and development, Mobile Apps development, Customized ERPs, CRMs, Web & Mobile Applications, eCommerce platforms etc. TechnoSoftwar deliver best Quality IT solutions on time. TechnoSoftwar having qualified and experienced IT professionals that works for your all business demands.

    ReplyDelete
  28. 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
  29. Maharashtra Police Wireless HC ASI Recruitment 2016


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

    ReplyDelete
  30. UP Urdu Teacher Recruitment 2016

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

    ReplyDelete
  31. 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
  32. Testing is the best in Information Technolgohy compared to anyother domain. Thanks for sharing your knowledge via this content. You have presented it very well. Thank you once again. I have bookmarked this page for future use. Keep blogging article like this.

    Selenium training in chennai | Selenium training institutes in chennai | Selenium training institute in chennai

    ReplyDelete
  33. Hi, actually I'am new to angularJs and infact I'am learning angularjs with online training. I'am having doubt, if you could solve the doubt for me that would be very helpful. The doubt is, how can I reset a “$timeout”, and disable a “$watch()”?
    Regards,
    angularjs training in Chennai|angularjs course in Chennai|angularjs training institute in Chennai

    ReplyDelete
  34. 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
  35. Cloud computing is the next big thing, through cloud the users have the liberty to use a shared network. The companies can focus on core business parts rather than investing heavily on infrastucture.
    cloud computing training in chennai|cloud computing courses in chennai|cloud computing training

    ReplyDelete
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. thanks for sharing this kind of valuable information.
    about this .net course which is useful and unforgetable article.
    CCNA Training in Chennai

    ReplyDelete
  42. 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
  43. well said about UML class diagram with its code. clearly understood about your concepts. keep update.
    Loadrunner Training in Chennai

    ReplyDelete
  44. 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
  45. 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
  46. 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
  47. This facade design pattern is awesome.It is to read and is easy to understanding format.
    Sharepoint developer training in chennai

    ReplyDelete
  48. 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
  49. 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
  50. 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
  51. 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
  52. 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
  53. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.


    Peridot Systems Chennai Reviews

    ReplyDelete
  54. 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
  55. 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
  56. 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
  57. 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
  58. 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
  59. 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
  60. 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
  61. 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
  62. 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
  63. لدينا مميزات في خدمات كشف تسربات التي تقدمها شركة ركن البيت التي تكون متخصصة فيها فتعاملك مع شركة كشف تسربات المياه بالدمام لديها امكانيات جيدة يساعدك علي التخلص من مشاكل التسريب التي توجد لديك بسهولة دون التعرض للخطر حيث نمتلك في شركة كشف تسربات بالدمام الامكانيات والفنين المتميزين الذين يقدمون الخدمة بتميز فاذا كنت فى حيرة من امر التسريب الذي يوجد لديك فعليك ان تعلم ان خدماتنا منتشرة في جميع انحاء المملكة مثل خدمات شركة كشف تسربات المياه بالرياض التي تحل لك المشاكل المتكررة المتعلقة بالتسربات فلا داعى للقلق من الان لانك سوف تملك فني جيد منزلك يحل لك كل مشاكل التسربات و كيفية القيام بهذه الخدمة وتذكر ان الحل الامثل فى شركة كشف تسربات بالرياض ان توفر كل الامكانيات التى تساعدك علي حل مشكلاتك

    ReplyDelete
  64. facade design pattern nice posts..

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

    ReplyDelete
  65. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Web Designing Course in Chennai | web designing training in chennai

    ReplyDelete
  66. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    salesforce training in chennai | salesforce training institute in chennai

    ReplyDelete
  67. 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
  68. Informatica provides a data quality services and data integration. It has the capability to fetch the data from different heterogeneous source. Bring your career in Informatica field. It has incredible breadth in future.
    Regards,
    Informatica Training Institute in Chennai | Informatica Training center Chennai

    ReplyDelete
  69. The strategy you posted was nice. The people who want to shift their career to the IT sector then it is the right option to go with the ethical hacking course.
    Ethical hacking course in Chennai | Ethical hacking training in chennai

    ReplyDelete
  70. Much obliged to you for requiring significant investment to give us a portion of the valuable and restrictive data with us.
    Regards,
    SAS Training in Chennai | SAS Course in Chennai | SAS Training Institute in Chennai

    ReplyDelete
  71. 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
  72. Thanks for sharing information to our knowledge, it helps me plenty keep sharing…
    Java Training in Chennai | JAVA Course in Chennai

    ReplyDelete
  73. Thanks for posting this useful content, Good to know about new things here, Let me share this,
    AngularJS Training in Chennai | AngularJS Training | Best AngularJS Training Institute in Chennai

    ReplyDelete
  74. 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
  75. You have done really great job. Your blog is very unique and informative. Thanks. Devops Online Training | Data Science Online Training

    ReplyDelete
  76. 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
  77. 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
  78. The best thing is that your blog really informative thanks for your great information!
    erp providers in chennai

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

    ReplyDelete
  80. I think this is interesting articles and Business ethics for new information's, and i like that kind of information.So the i like that post,because all of given information was very excellent.devops jobs in Hyderabad

    ReplyDelete





  81. 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
  82. I read this article. I think You put a lot of effort to create this article. I appreciate your work.

    PhD Thesis Writing Services
    Dissertation Writing Services
    Research Paper Writing Services

    ReplyDelete