|
This design definitely has his reasoning:
protected members:
The class it belongs to, and more importantly, the member functions of any derived class of the class it belongs to can access it. If you think that you may use a class as a base class for other classes in the future, any derived class may need Accessed data members should be set to protected. Instead of private, this ensures that this class is "suitable for inheritance."
Dangers of protected members:
Let's say you write a class library and intend to distribute it as public. Any programmer who bought this library can simply derive other classes from it to access the data members of the protected class, which makes Protect members' security much lower than private ones,
To prevent data corruption, derived classes are usually forced to use only public functions of the base class to access the data.
in conclusion:
The use of protected indicators makes program design easy, but when you really use it, you have to weigh the rights and disadvantages!
Ha ha!! |
|