Abstractions in Object Oriented Programming
What is Abstraction
An abstraction, rather than something real or observable, is a general notion or idea. Abstraction has a similar concept in Computer Science. It's a condensed version of something technical, such as a software feature or an object.
The goal of "abstracting" data is to minimize complexity. By looking at distinct instances, it is simpler to grasp abstraction. For example, when you are driving, you only need to know about the basic functionalities of the car, like how the steering, brakes, and AC works. You are not going into much detail about the internal workings of the car. The internal technicalities of the car are abstracted from you.
The same is in the case of programming, there is some information that is not important for users. One of the main principles of object-oriented programming (OOP) languages is abstraction. Its main objective is to deal with ambiguity by concealing unnecessary information from the user. That allows the user, without knowing or even worrying about all the hidden complexities, to go about their tasks. This is a rather general term that is not limited to programming that is object-oriented. In the real world, you will find it anywhere.
How Abstraction works
In computer programming, abstractions are particularly important, where many specifics are at first left out in order to make programming simple for beginners. This is particularly noticeable in drag-and-drop languages, where blocks are used for program development instead of text. Languages like Snap! and Scratch are drag-and-drop languages that make it easy to program complicated objects using abstractions. With text languages, programming abstractions are also present. In all languages, abstractions are usually created using "methods” and “attributes."
Methods are processes that the programmer creates, which are then summarized in a single block/line that the user can use either a block or a line of text (depending on whether the language itself is block-based or text-based).
Abstraction, an example
Take for example the image below. It is a code segment taken from the programming language Snap!.
This is an abstraction created to simplify the overall code to draw a square. When defining drawSquare it creates the algorithm to be used in the overall program.
Here is the abstraction put into the overall program. After the 4 key is pressed and the user enters how long they want the side length to be, the program will use that input and run it through the drawSquare abstraction to draw a full square. To ‘draw a square’, the user need not know the technical details of how it is actually created but using some simple clicks they are able to can draw the square.
Comments
Post a Comment