Recently done a little miscellaneous, exposure to several object-oriented language, C#,c++,java. In one scenario, the software framework has been written, and we want to add and modify its functionality, which is often happening, so what do we do in object-oriented program design? We all know that object-oriented language has several characteristics, polymorphism, encapsulation, inheritance, since the framework has been written, we modify the function can be considered to use the inherited method to implement the new function, then this will affect the original function? This involves the change in the visibility of member variable member methods in inheritance.
First, we look at C + +
Derived classes inherit the members of the base class as part of themselves, but different inheritance methods cause the members of the base class to have different properties in the derived class. We first use the access properties that represent that the base class member inherits after it will behave in a derived class:
is a single-inheritance approach and does not involve the derivation of derivations again. But both of these situations can be deduced using the logic of the diagram. As in the case of derivation again, it is possible to treat a derived class as a base class.
Here we already know the properties of the members in the base class in the inheriting class, and then we detail the visibility problem by an angle.
How to Inherit |
Public inheritance |
Protected inheritance |
Private inheritance |
Base class member properties |
Public |
Protected |
Private |
Public |
Protected |
Private |
Public |
Protected |
Private |
Base class members on their objects |
Visible |
Not visible |
Not visible |
Visible |
Not visible |
Not visible |
Visible |
Not visible |
Not visible |
Base class members for derived classes |
Visible |
Visible |
Not visible |
Visible |
Visible |
Not visible |
Visible |
Visible |
Not visible |
Base class member on derived class object |
Visible |
Not visible |
Not visible |
Not visible |
Not visible |
Not visible |
Not visible |
Not visible |
Not visible |
The change of visibility of object-oriented language member variable method in inheritance