Wrapper Facade Pattern

Source: Internet
Author: User

Wrapper Facade Pattern is used to encapsulate low-level functions and data structures in Interfaces of high-level facial objects. Class libraries that use this mode include MFC and Ace. They encapsulate the c api and data structure provided by the low-level operating system in the CPP interface.

Why do we need to use wrapper Facade Pattern to encapsulate the c api provided by the system:
1. The c api uses too many weakly typed parameters, such as handle. The weak typed parameters weaken the compiler's ability to check types and increase the program's unstable factors. // Use the weakly typed parameter <br/> bool uplev( objid idplayer) <br/>{< br/> If (! Isplayerid (idplayer) // the task of checking the compiler is handed over to the programmer <br/> return false; <br/> //... <br/>}< br/> // use unweakly typed parameters <br/> bool uplev( cplayer & player) <br/> {<br/> //... <br/>}2. The c api provided by the system cannot be transplanted. Even if we do not plan to write programs across the operating system platform, we must consider the differences between different compiling platforms of the same system. The simplest example is, assert in vc6 is different from assert in vs2008. We should always encapsulate the API provided by the system so that the program can be flexibly migrated to different platforms. 3. encapsulation of c api is the basis for compiling the framework. The framework is a powerful tool to solve the essential complexity. Wrapper Facade Pattern solution: encapsulate related functions and data structures in one or more wrapper facade classes. The wrapper facade mode is relatively simple. Obviously, it has only two participants: 1. Wrapper facade2. Functions
Here are some guiding principles for how to better compile wrapper facade: 1. familiar with the functions provided by the functions to be encapsulated 2. familiar with abstract concepts of fields (we need to understand the big questions in related fields) 3. for a specific abstraction, it identifies the associated functions and data structures. This set of functions and data structures will generate one or more wrapper facade class4. this article does not complete the functions in a group.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.