Imagine if they didn't have their store front, and you wanted to find out if your item was in stock and how much it was. You would probably call up the closest store to you and ask about the product, they might not know exactly how much stock they have, so they go and check and tell you that they have 0 items in stock but you should try calling the store in the next town, maybe they have some in stock, so you call over there, no luck, finally you find a store 3 towns away but their price is $10 more because they are in a wealthy town and the rent is higher. So you could go through all this trouble OR you could just use their website and when you click on a product it goes out to all the stores near you, gathers inventory data and presents you with your standard price.
The same concepts apply to software development. An example would be Amazon... Amazon.com allows a developer access to certain API's they are allowed to use. You can search for products, maybe check inventory, and some other useful things. Now lets say you're running your company with all this money poured into a fancy web system that manages your products and orders. You like what amazon has done but you cannot afford to rewrite a whole system just for people to interact with on their website. You want an alternative.. you want the FACADE pattern. Using the facade pattern you can create a "Public API" class in your system that contains methods that you want people to have access to, like getPrice(), or getInventory(). In reality your system isn't so simple, in your system you can manage stock, track orders, fullfillment, order allocation, warehousing, etc but imaging giving a user a 400 page API map of your system, besides the security issues it just wouldn't work.
So using the facade pattern you can open up only the parts of your system you want people to use, maintaining a SINGLE point of entry to your application. Lets imagine for a minute that you don't have your Public API class and you're letting users use your api's directly and lets say something happened in the future that required you to change your Pricing class, it couldn't be helped it had to change, well this would break all your existing clients connection to your site. If you had the Public API class in place you could change out anything you wish so long as the getPrice() method of the Public API returned what the client expected. Take a look at the UML Graphs below.
To relate this to PHP consider the JPGraph Library (http://www.aditus.nu/jpgraph/) which is a 3.8 MB package that allows you to display pretty graphs of data on your website. Let's your boss comes to you with a project. He wants you to incorporate a graph on your website that you and your teammates can use to generate a line graph showing hits to your website over a period of time that your developers can dictate. Your teammates also want to use this feature on pages they're coding but can't take the time to learn JPGraph (which can be involved). So its your job to make this feature as easy as possible so you create a Facade class to interact with JPGraphs library of classes. So you create your JPGraphFacade class so your developers can use it like this:
- $line_graph = new JPGraphFacade();
- $line_graph->showLineGraph($data, $timePeriod);
Try downloading JPGraph and see if it could really be that easy to create your own graphs. You just saved your teammates alot of time and headache because you gave them a great interface to only a feature they needed of a much larger library. If your boss decides later on that he wants to add bar charts you can just modify your Facade class and let them use it like this:
- $bar_graph = new JPGraphFacade();
- $bar_graph->showBarGraph($data, $timePeriod);