Data Hiding In Java

Data Hiding is a facet of Object Oriented Programming (OOP) that allows developers to safeguard private data and conceal implementation details. Within this tutorial we analyze basic data hiding techniques in Java. We also provide illustrations. Object Oriented Programming provides approaches for modeling entities in the ‘real world’. It’s been observed that humans relate with real world things as objects.

Objects have two basic characteristics, which we will briefly discuss here. This list could be extended and it is not designed to be complete at all indefinitely. The concept of Data Hiding is primarily concerned with the first category of characteristics, which are described simply as data here.

In Java, a class is a programmer-defined data type that has data and code (make reference to the two types of characteristics listed above). The term user refers to software programmers and system designers who apply a class in a larger program. Note that this definition of the term user might be contrary to common parlance.

We are not referring to the end-user of a credit card application program. That definition is certainly valid, however, not in this framework. We differentiate between the writer of the Java class and an individual of the Java course. Both are humans, both have comprehensive software development knowledge, and both understand OOP concepts.

  • Main Street Sandwich Company
  • 2009 = 1,000
  • 10,000 medium-sized companies paying you $10k+ per season each; or
  • Turn the Kirby vacuum on by pressing the on/off button at the back of the electric motor

Conceptually, the primary difference between your two humans is that the class writer has domain knowledge and an individual may not. Domain knowledge is the understanding of a real-world entity in order to model it with a software object. All programming obligates some area knowledge. For instance, a human who knows how to build a telephone may have the domain name knowledge essential to devise a software model of a phone.

Domain knowledge is ‘built-in’ to a software course. A user, on the other hand, can gather some domain knowledge from a preexisting software class but might not possess sufficient knowledge to really program that model. Class users typically need not see the execution details of classes they utilize in their programs. Hiding the facts actually increases productivity because course users are not required to read reams of source code that has already been debugged by developers with area knowledge.

In a perfect world, class users make reference to class paperwork (JavaDocs for example) rather than browsing class source code to discern features. Data Hiding shields implementation details from course users and provides a convenient platform for enforcing data integrity guidelines on the class developer aspect. We demonstrate both principles in the following source code. Generally, all variables in a class should be private.