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.