Abstraction (?) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Abstraction (?)

What does Abstraction means ? Give Explanation with Example ( If You Know ) :)

15th Dec 2017, 9:22 PM
Ripon Roy Sporsho
Ripon Roy Sporsho - avatar
2 Answers
+ 1
It's like making an object but you don't want it totally as the object itself. Abstraction is something very "in general" for children classes. We will have a figure class which will be abstract. As we know, a figure can have different attributes and methods: name, area, perimeter, number of sides, etc. calculateArea(), calculatePerimeter(), for example. We can declarate attributes. We can declarate methods but they can't have a body, this is because the children classes will implement and "give" them a body. Example: //first our abstract class public abstract class Figure{ int height; int n_sides; int base; public float calculateArea(int base, int height ); public float calculatePerimeter(int n_sides); } //we will have just one child class public class Rectangle extends Figure { public Rectangle(){ } public float calculateArea(int base, int height){ return base*height; } } As we can see we implemented the method calculateArea in the rectangle class and d we defined how the area will be for this type of figure. it's simple Example, but I hope you have understood. That's what I remember about abstraction.
15th Dec 2017, 10:01 PM
jaaxdev
jaaxdev - avatar
+ 1
Abstraction is a way to simplify your app design and concentrate only on a valuable parts. For example if your app should manage employees records, each employee will have only few valuable characteristics, like name, position, phone number etc. So when you will be creating class Employee it will have only those fields, but it probably will not have fields for storing color of hair or weight of employee, since they doesn't used in your app, although each employee has such characteristics. Abstraction it is the part of design process when you make decision what characteristics are main for your app and what you can skip.
15th Dec 2017, 9:51 PM
Dima Makieiev
Dima Makieiev - avatar