difference between data hidding, encapsulation, abstraction

First, Abstraction is simply separating the top level usefulness of a thing from the details of its implementation. As a user of a control, you really don't care how the control does its job, what kernel operations it invokes, what interrupts it might raise. You only care what methods it has for you to call, and what results to expect of them. That's abstraction at work; keeping the details away from the consumer of the object, so that the programmer is freed from worrying about details that aren't relevant to his assignment.

Second, Encapsulation is simply combining the data members and functions into a single entity called an object. This may seem trivial to you, but when it was first proposed it was very hard to grasp. In the early days we had, within a program, a data region and a code region, dedicated at compile time. The concept of objects, which were self-contained entities comprised of their own functions and data items was really hard to embrace, but ultimately it was very useful to understand and adopt. When combined with the concept of abstraction, this gave us the opportunity to write truly reusable code. So long as we didn't change the methods and data members exposed to users, we could modify the internal implementations of our objects as much as we wanted to, without breaking any applications which depended on them.

Lastly, Data Hiding has to do with restricting access to internal variables used by an object to perform its magic. Originally, data hiding was proposed to protect these internal data items from being modified by users of an object. The Private access modifier was introduced to provide that protection. The concept has evolved to embrace protection of all object data members from outside manipulation, by introducing the concept of Properties (in C#, at least). As a rule, member data items are not accessible outside of the class which defines them. The programmer must explicitly define a get or set method to allow another object to read or modify these values.

Although many programmers today take these concepts for granted, they were world shaking ideas when they first appeared, and very difficult to grasp. I can recall when Turbo Pascal 5.5 was released, and that was my first introduction to OOP and these fundamental concepts. It shattered everything I knew about programming, and forced me into a whole new way of thinking about software. I wonder what the next great paradigm shift will bring? You'll probably be around to see it, but I might not, thankfully...

Comments