At some point in PHP development, programmers will discover a need to:
make a software library easier to use and understand, since the facade has convenient methods for common tasks;
make 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 (As per task needs).
In the Facade Pattern a class hides a complex subsystem from a calling class. In turn, the complex subsystem will know nothing of the calling class.
Definition
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. This can be used to simplify a number of complicated object interactions into a single interface.
Example
In this example, the CaseReverseFacade class will call a subsystem to reverse the case of a string passed from the Book class. The subsystem is controlled by the reverseCase function in the CaseReverseFacade, which in turn calls functions in the ArrayCaseReverse and ArrayStringFunctions classes. As written, the CaseReverseFacade can reverse the case of any string, but it could easily be changed to only reverse a single element of a single class.
In my example I make all elements of the Facade and the subsystem static. This could also easily be changed.
Hi, I am Vinod working as a Sr. Software Developer on PHP, MySql, Linux, Ajax etc. for last 4 years. This blog is a medium to share some thoughts & experiments of mine which I've experienced in the span of my professional career.
The Information in this weblog is provided "AS IS" with no warranties and confers no rights. This webLog does not represents the thoughts, intentions, plans, startegies, information about/of my employer. This is solely my thoughts which i want to share across. My thoughts and opinions might change from time to time as i learn more and develop deep knowledge about things which i write here.
0 comments:
Post a Comment