+ 4
What's the practical use of abstraction pls explain me, thanks in advance
6 Answers
+ 10
I can try to give some example when abstract classes are useful.
Java has a very intuitive class.util.Calendar. Its arsenal has a lot useful and necessary functions, but there is one feature - it does not implement a particulare calendar. People in the world live in different calendars. Gregorian, Russian Orthodox Church and even Martian calendar if you are on Mars.
As you can see the calendars have differences, but it is not surprise if you are told that the opportunity to add 3 days to any date must be present in all cases. So, all these calendars have a common set of features, which can have the same realization. The idea of abstract class was born from here..Abstract class on one hand cannot create objects, on other hand may have a ready set of functions.
The creation of abstract class is quite complex architectural problem. The need to use an abstract class appears not immideately. It is required to analyze the problem and a set of classes, which will take a decision.
I hope it will help :)
+ 4
I can give an example, that is the collection framework. List is an abstract class, describling list features. However, we should implentment it by arraylist and so on.
+ 4
or example if you are connecting two computers through java sockets. you must have two give IP address of remote computer. without giving IP address its impossible to connect both computers. so within Java socket class they make abstract method setIpAddress. which is compulsory for every child class to implement.
+ 3
really helpful answers here...thank you. I also like the youtube video called "Abstraction - A Programming Concept" by lcc0612. It's 7:50 in length.
www.youtube.com/watch?v=ZJocPKDVQSc
+ 3
Another shorter one. 1 minute 11 seconds
Project GUTS
"Computer Science Concept-Abstraction"
www.youtube.com/watch?v=0w_rla7Godl
- 1
The whole language of Java is based on abstraction
Class is the best example.
Think yourself...