List the drawbacks of classes with all public data members. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

List the drawbacks of classes with all public data members.

C++ question

30th Sep 2020, 4:24 PM
Sneha Bhatnagar
Sneha Bhatnagar - avatar
2 ответов
0
Well if something is public, chances are it is already being depended upon in another class. It may be therefore costly to change its implementation. But if it is private, you can change its implementation in a whim, has long has the public API still works correctly. This is called data hiding and is a important part of encapsulation, one of the major pillars of OOP.
30th Sep 2020, 5:17 PM
Ore
Ore - avatar
+ 5
you cannot say drawback . If you will read definition of public members u will understood the drawbacks and advantage both . everyone want to access data so public is better ...... 😆😆😂 public member is accessible from anywhere outside the class but within a program. You can set and get the value of public variables without any member function  Access modifier provides you the authority to control your data depending upon the scenarios. If you are working in a bank domain then you have to use private data members to keep your data hidden from other users, authority is in your hand. You can make them public if you want to but it won’t be a great approach because in that case, anyone can change your data at any time
30th Sep 2020, 5:02 PM
A S Raghuvanshi
A S Raghuvanshi - avatar