Objects and Data Structures – Data Abstraction

Object Oriented Programming (OOP) is a programming paradigm in which we use real world concepts or objects and create abstractions that will represent them in our software.

Data Abstraction

When we create an abstraction to represent a real world concept or object, we have to decide what that abstraction will expose and what it will hide (private fields, public properties and methods).

Why does the concept of public and private exist in OOP? Because there are things we don’t want our objects to share with other objects. We want our abstractions to expose to other objects the things that they can do or the data they offer, but not tell others how they do them or how that data is stored. Those details are private and should only be known to the object itself.

An example of a good abstraction

Think about a cell phone. Most people have no idea about how their phone works, yet they know very well how to use it. The technical details that actually make the phone work are private and known only by a few people, yet everyone knows that they can store their contacts in it and make phone calls with it.

A good abstraction tells exposes what an object can do, but hides the way that it happens. This makes changing the private aspects of the abstraction invisible to the user of that abstraction.

When a new model of your cell phone comes out, it doesn’t matter if the technology behind it is the same as the one you have or it’s something completely different. As long as the public aspects of it are the same, you can use it just as well as the one you have now.

Good abstractions expose what an object can do, but hide the way it does it.

Leave a Reply