Re: What is Data Hiding?

Posted on 2 years ago

Encapsulation is more about keeping a group of code as a discreet work unit but it also has data hiding because you only expose "the method" rather than its inner workings to other classes. Encapsulating leads to data hiding, so that's why it sounds similar.

Data hiding on its own it by only marking those things as a public scope which you want external classes to interact with, and private otherwise. If you don't want other classes or only certain classes to use, you can also use private (current class only), protected (current and children), and internal (treated as public to other classes in the same assembly, private to outside assembly classes) to prevent other classes beyond a certain scope from using your methods/properties/classes.