Abstraction in Computer Programming
The concept of abstraction will be introduced to you early in your computer programming career. Abstraction is simply the concept of taking more complex code and hiding it from the user (or programmer) to allow him or her to interface with a programming language in a more user-friendly manner.
For instance, everything in a computer programming language must be coded—everything that the programming language does must be coded. So if I want to write something in a document and display it on the screen, I could write:
document.write(“Display something on the screen.”);
document.write( ) is actually a method that has already been created within the JavaScript language. It is a set of code that allows you to write something directly into an HTML document and therefore display when that HTML is shown in a browser.
You don’t see the code that’s included in document.write( ), but you know that you can use it. That’s an example of abstraction. It makes it a lot easier for you to use JavaScript if you can use pre-coded methods to do common things that would otherwise take you a long time to do.
It is often compared to driving a car.
🚗
You don’t have to understand all of how a car works in order to drive it. You can simply get into a car and turn the key…you don’t necessarily know all of the processes that take place to start up that car, but you can put the key in, turn it and go.
That’s what you are doing when you use a pre-coded method (or function) in a programming language. You use the code, give it a value if you need to and you can use it in your program.
You don’t need to know everything it takes to start up a car and make it work, all you have to do is turn on the engine and decide where you want to go—that’s abstraction.