Chapter 2 C ++ object-orientedProgramDesign method Overview
Encapsulation, inheritance, combination, virtual functions, abstract base classes, dynamic binding, and polymorphism are important concepts in object-oriented programming.
12.1 introduction to object-oriented
12.2 Object Concept
12.3 Information Hiding and class Encapsulation
The most fundamental change of C ++ to C is to put the function into the structure, resulting in a C ++ class. The most taboo for learning C ++ classes is to treat classes as hot pots and throw everything in them.
Inheritance of class 12.4 (is-a-kind-)
For C ++ programs, it is easier to design isolated classes. What is more difficult is to correctly design the base classes and Their Derived classes.
Inheritance is useful and easy to use, but it must be prevented from abuse!
Is-a-part-)
One principle of programming is to prioritize combination (Delegation) rather than inheritance.
12.6 Dynamic Features
In most cases, the functions of a program are determined during compilation, which is called static features. If the function of a program is determined at the runtime, it is called a dynamic feature.
Abstract base class: class with pure virtual functions.
Virtual void draw (void) = 0; // pure virtual function
Explanation of pure virtual functions: we know that,The function name is the function address. initializing a function to 0 means that the function address will be 0, which means that the compiler should not compile the function, this prevents class instantiation.
12.7 C ++ Object Model
The object itself contains only data! Any member function does not belong to any object. The relationship between a non-static member function and an object is bound, and the bound intermediary is the this pointer.