Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

abstraction vs abstract class

Tags:

oop

according to http://www.cs.cornell.edu/courses/cs211/2006sp/Lectures/L08-abstraction/08_abstraction.html

abstraction comes in two flavors. One is function abstraction and the other is data abstraction. But where do abstract classes fit in? As far as i see, abstract classes are a totally different concept and even though the name suggests that it has something to do with OOP principles.

Could someone please shed some light on this ?

like image 577
crowso Avatar asked Sep 26 '12 02:09

crowso


People also ask

Is abstraction and abstract the same?

While both share the departure from the representational or literal depiction of objects, scenes, figures, etc., abstraction implies that the work still has roots in the physical. Say, an abstraction of flowers or figures. Abstract art, on the other hand, has a clean break from reality.

What is abstraction and abstract class in Java?

In java, abstraction is achieved by interfaces and abstract classes. We can achieve 100% abstraction using interfaces. Abstract classes and Abstract methods : An abstract class is a class that is declared with an abstract keyword. An abstract method is a method that is declared without implementation.

What is difference between abstraction and interface?

Abstract Class Vs. Interface: Explore the Difference between Abstract Class and Interface in Java. The Abstract class and Interface both are used to have abstraction. An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class.


1 Answers

These are very different concepts.

Abstraction is similar to the concept of a black box. Input goes in, black box does something, output comes out. It doesn't matter what happens in the black box, all you have to know is that it works. A real life example of this is java's hash function, all the user has to know is that it hashes the input value, it doesn't matter to the user how the number gets hashed. The black box is the abstraction. The point is you don't have to know how it works, just that it does.

Abstract classes (at least in Java) are a mixture between interfaces and full OOP classes. An interface defines methods that any extending class must have, its an agreement in the code that it will implement the interface properly and assures everything will work as expected. An abstract class has these empty methods(agreements) and also has fully implemented methods that can be called.

like image 104
Scott Avatar answered Sep 20 '22 15:09

Scott