& Nbsp; the appearance mode hides the complexity of calling objects by creating a simple appearance interface before the set of required logic and methods. The appearance design mode is very similar to the builder mode. The Builder mode is generally used to simplify the complexity of object calling. the appearance mode is generally used to simplify the complexity of many logical steps and method calls. In the application scenario, design a User class, which contains the getUser interface for getting User information. when using the getUser interface, set the appearance mode.
By creating a simple appearance interface before the set of required logic and methods, the appearance design mode hides the complexity of calling objects.
The appearance design mode is very similar to the builder mode. The Builder mode is generally used to simplify the complexity of object calling. the appearance mode is generally used to simplify the complexity of many logical steps and method calls.
Application scenarios
Design a User class with the getUser interface for getting User information
When using the getUser interface, you must set the user name and age.
Therefore, in normal cases, to call the getUser interface, you need to instantiate the User class, set the User information, and then call the getUser method. this process is complex. if there are many User information, or changing, calling User information will be costly, for example, adding information such as the user's mobile phone number, address, weight, and marital status as the business expands.
A UserFacade is designed with a static method getUserCall, which can directly call the getUser function.
Code: getUser class
UserName = $ userName;} public function setUserAge ($ userAge) {return $ this-> userAge = $ userAge;} public function getUser () {echo 'user name :'. $ this-> userName. '; user age :'. $ this-> userAge ;}}
Code: UserFacade user class appearance interface, a getUserCall interface
// Create a User class Call Interface to simplify the call class UserFacade {public static function getUserCall ($ userInfo) {$ User = new User; $ User-> setUserName ($ userInfo ['username']); $ User-> setUserAge ($ userInfo ['userage']); return $ User-> getUser () ;}$ userInfo = array ('username' => 'initphp', 'userage' => 12); UserFacade :: getUserCall ($ userInfo); // A function can simplify the call class.