Thursday, 4 January 2018

Design Patterns | Facade pattern

The facade pattern is a wrapper of many other interfaces in a result to produce a simpler interface.

Facade hides the complexities of the system and provides an interface to the client from where the client can access the system easily. A facade is an object that provides a simplified interface to a larger body of code, such as a class library.






Example
This is an abstract example of how a client ("you") interacts with a facade (the "computer") to a complex system (internal computer parts, like CPU and HardDrive).

/* Complex parts */
class CPU {
      public void freeze() {
            ...
      }
      public void jump(long position) {
            ...
      }
      public void execute() {
            ...
      }
}

class Memory {
      public void load(long position, byte[] data) {
            ...
      }
}

class HardDrive {
      public byte[] read(long lba, int size) {
            ...
      }
}

/* Facade */

class ComputerFacade {
      private CPU processor;
      private Memory ram;
      private HardDrive hd;

      public ComputerFacade() {
            this.processor = new CPU();
            this.ram = new Memory();
            this.hd = new HardDrive();
      }

      public void start() {
            processor.freeze();
            ram.load(BOOT_ADDRESS, hd.read(BOOT_SECTOR, SECTOR_SIZE));
            processor.jump(BOOT_ADDRESS);
            processor.execute();
      }
}

/* Client */

class Facade {
      public static void main(String[] args) {
            ComputerFacade computer = new ComputerFacade();
            computer.start();
      }
}

Points to remember about façade design pattern
1. Wrap a poorly designed collection of APIs with a single well-designed API.
2. 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;
3. Facade design pattern is more like a helper for client applications; it doesn’t hide subsystem interfaces from the client. Whether to use Facade or not is completely dependent on client code.
4. Facade design pattern can be applied at any point of development, usually when the number of interfaces grows and the system gets complex.
5. Subsystem interfaces are not aware of Facade and they shouldn’t have any reference of the Facade interface.

We can use Factory pattern with Facade to provide the better interface to client systems.

Sources

42 comments:

  1. Your potential customers are actually counting on local and cellular search engines and directories to locate - and visit - search engine optimization support.
    professional logo design services

    ReplyDelete
  2. https://hemphousenc.com/ Cool stuff you have got and you keep update all of us.

    ReplyDelete
  3. http://cuttingedgewindowtinting.co/ This content is written very well. Your use of formatting when making your points makes your observations very clear and easy to understand. Thank you.

    ReplyDelete
  4. landscaping We are a professional detailing services company serving Harford and Baltimore counties in northern Maryland. Call (443) 756-3000 for all your detailing needs

    ReplyDelete
  5. CBD hand sanitizer We are Tennessee’s first and only CBD/Hemp Dispensary owned and managed by a Pharmacist and staffed by Medical Professionals certified in Cannabinoid Pharmacotherapy. We offer an environment that is warm and inviting.

    ReplyDelete
  6. https://www.emergencyelectriciangreensboro.com/blog/24-hours-electrician-best-electrician-of-greensboro At Emergency Electrician Greensboro, we understand how much you rely on electrical energy to power your everyday life. Fortunately, we are experts regarding safeguarding against its inherent risks and are all ready to do the reliable labor had to make sure your home's power systems work for decades to come.

    ReplyDelete
  7. Fayetteville NC Once Upon A Child® buys and sells gently used kids' clothing, shoes, toys, and baby gear. We pay you cash on the spot and provide a convenient way to recycle the items your children have outgrown, giving those items a second life. Every day you’ll find an ever-changing selection of top name brands at up to 70% off regular retail prices. Get paid and save for being eco-friendly!

    ReplyDelete
  8. Fayetteville NC At Plato's Closet, we buy and sell gently used clothes, shoes, handbags, and accessories for guys and girls in their teens and twenties. We have all the name brands and styles you love at up to 70% less than regular retail prices. We look for brands such as american eagle, free people, nike, urban outfitters, adidas and many many more...

    ReplyDelete
  9. Fayetteville NC Clothes Mentor sells gently used name-brand and designer clothing, shoes and accessories for up to 70% off of original retail prices. Our stores only stock pieces that are in great condition and are on-trend or classic and timeless. Clothes Mentor pays CASH On-the-Spot or store credit for clothing in sizes 0 to 26 and maternity as well as shoes, handbags and other accessories.

    ReplyDelete
  10. Customers can expect a responsive and supportive partner.
    website designer company

    ReplyDelete
  11. We do all the things around your home or business that you don’t have time to do or want to do.
    We give you freedom to focus on what’s important to you and spend time doing the things you love.
    We provide Detail landscaping, cleaning, painting, pressure washing, deck refurbishing, mulching and auto detailing services for
    homeowners and business owners in Harford County, Baltimore County, and Cecil County.
    thedetailguysmd.com/

    ReplyDelete
  12. where to get your windows tinted near me We provide the best in Car Window Tinting, Residential and Commercial tinting in Elgin IL. 100% Satisfaction Guaranteed. Call us today at 847-429-8775.

    ReplyDelete
  13. 7 chi Brookside CBD Wellness Center is a CBD shop that is owned by a professional pharmacist in East Tennessee. We understand how therapeutic CBD is and the healing

    ReplyDelete
  14. how to install metal roofing on a shed With years of working with insurance providers and complete storm disaster restoration, there's nothing the RADIN team can't handle

    ReplyDelete
  15. how to calculate cbd content The idea of Terry’s Naturals and owning and selling hemp-based products began in 1989 when Terry Dawn Behrman began her education in the properties of hemp. Living and working in Colorado the wander lust soon took her after she had her first child in 1990. By 1994 she took her education on the road

    ReplyDelete
  16. ceramic window tint We provide the best in Car Window Tinting, Residential and Commercial tinting in Elgin IL. 100% Satisfaction Guaranteed. Call us today at 847-429-8775.

    ReplyDelete
  17. The Whaley Center Fayetteville NC After a year plus of careful construction, we are proud to announce the opening of The Whaley Center featuring Plato’s Closet, Once Upon a Child and Clothes Mentor! We are located conveniently at 4544 Yadkin Road. When finding the proper location for The Whaley Center, we wanted to find a location that would accommodate the needs of three full-sized stores.

    ReplyDelete
  18. Inspirational Book to change your life Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also

    ReplyDelete
  19. Delta 10 THC iHemp have been serving High Point and Winston-Salem since Feb 2019. We strive not only to give you great CBD products, but also great customer service.

    ReplyDelete
  20. Fries and best pizza delivery Greensboro NC Moe’s Pizza and Subs is more than just your go-to for quality homemade food, it’s a Greensboro staple. Located conveniently off of Bridford Parkway on

    ReplyDelete
  21. Lashes and Makeup At Pinup Studio here in Raleigh, North Carolina, all of our services revolve completely around you, our valued client! Our salon floor is set up to be a wonderfully relaxing space for you to just sit back, relax, and enjoy our quality services and a drink. Pamper yourself with our high-quality services and let yourself embrace your inner Queen! Whether you are a woman in the workforce, a working mom, a stay-at-home mom, or a woman just living her life, you deserve to indulge in some self care and get your hair and makeup done with us.

    ReplyDelete
  22. CBD oil Brookside CBD Wellness Center is a CBD shop that is owned by a professional pharmacist in East Tennessee. We understand how therapeutic CBD is and the healing

    ReplyDelete
  23. cedar mulch Professional landscaping, auto detailing, junk removal, pressure washing, painting, deck restoration, commercial cleaning services in Harford County, MD.

    ReplyDelete
  24. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website.
    coleman sportsman waterproof first aid kit

    ReplyDelete
  25. Is cbd addictive The most highly procured essential oils, herbs, and CBD products--including CBD oil Colorado Springs and Pueblo have to offer!

    ReplyDelete
  26. roofing nails With years of working with insurance providers and complete storm disaster restoration, there's nothing the RADIN team can't handle! We Are Best Roofing Company Of Utah

    ReplyDelete
  27. car window tint film We provide the best in Car Window Tinting, Residential and Commercial tinting in Elgin IL. 100% Satisfaction Guaranteed. Call us today at 847-429-8775.

    ReplyDelete
  28. Thanks for the blog post buddy! Keep them coming...
    CBD Gummies

    ReplyDelete
  29. junk & Trash removal Milwaukee We do the heavy lifting, so you can focus on your latest project!

    ReplyDelete
  30. Once Upon A Child Fayetteville NC Welcome to The Whaley Center, Fayetteville’s premier destination for an affordable, convenient, and conscientious shopping experience.

    ReplyDelete
  31. Thank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info.
    Best CBD in Winston Salem NC

    ReplyDelete
  32. cake disposable vape This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info:

    ReplyDelete
  33. buy used clothes Once Upon A Child® buys and sells gently used kids' clothing, shoes, toys, and baby gear. We pay you cash on the spot and provide a convenient way to recycle the items your children have outgrown, giving those items a second life. Every day you’ll find an ever-changing selection of top name brands at up to 70% off regular retail prices. Get paid and save for being eco-friendly!

    ReplyDelete
  34. Fayetteville NC At Clothes Mentor in Fayetteville, NC we believe we can be the difference in the world. By recycling and reusing current fashions we are creating a sustainable lifestyle that you will be proud to be a part of. At our stores you can find like new designer clothing at up to 70% off mall store prices. All of our clothing, shoes, handbags, and accessories are gently loved, and actually like new. We only buy pieces that are in great shape, on trend, or classic and timeless.

    ReplyDelete
  35. buy used clothes At Plato's Closet, we buy and sell gently used clothes, shoes, handbags, and accessories for guys and girls in their teens and twenties. We have all the name brands and styles you love at up to 70% less than regular retail prices. We look for brands such as american eagle, free people, nike, urban outfitters, adidas and many many more...

    ReplyDelete
  36. This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog..
    coleman 6-person dark room fast pitch dome tent

    ReplyDelete
  37. roofing nails I started in the construction trade when I was a kid and slowly worked my way up to running my own construction company in New Mexico. Roofing and storm restoration were always my main focus

    ReplyDelete
  38. edgewood landscaping Landscaping, pressure washing, deck restoration, auto detailing, commercial service, painting and mulching is being done by the detailed guys.

    ReplyDelete
  39. moes subs At Moe's we believe that life is better with pizza. We are a fast-casual restaurant serving handcrafted pizzas, fresh salads, and decadent desserts. Order online for carryout or delivery today!

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...