Proxy mode + valid tive C ++ Chapter 1 notes

Source: Internet
Author: User

Proxy mode + valid tive C ++ Chapter 1 notes

Proxy: provides a Proxy for other objects to control access to this object.

Application:

(1) remote proxy, which provides a local representation of an object in different address spaces. This will hide the fact that an object exists in a different address space.

(2) virtual Proxy: Creates objects with high overhead as needed. It takes a long time for a real object to be instantiated through a virtual proxy.

(3) Security Proxy, used to control the permissions of real objects.

(4); smart pointer: when calling a real object, the proxy handles other things.


Valid C ++:


1: Check whether the object has been initialized before it is used.

(1) manually initialize the built-in types because C ++ does not guarantee that they are initialized.

(2) It is recommended that the function use the member initial column (member initialization list) instead of the assignment operation in the constructor ). The member variables listed in the initial column should be sorted in the same order as their lifecycles in the class.

(3) Replace the non-local static object with the local static object (Singleton mode) to avoid the issue of "cross-compilation warm initialization order)


2: constructor/destructor/value assignment


(1) the compiler can create default constructor, copy constructor, copy assignment operator, and destructor for the class.

(2) to reject the skills automatically provided by the compiler, the corresponding member functions can be declared as private and not implemented. Using base classes like Uncopyable is also a practice.

class Uncopyable {protected:    Uncopyable() {}    ~Uncopyable() {}private:    Uncopyable(const Uncopyable&);    Uncopyable& operate=(const Uncopyable&);};

(3) polymorphic base classes should declare a virtual destructor. If the class has any virtual function, it should have a virtual destructor.

(4) virtual destructor should not be declared if they are not used as base Classes or for polymorphism.



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.