Quick Index
Overview
An abstract type is an idea.
If something is abstracted, it means the details are hidden.
Abstract Versus Concrete
Let's revisit this example:
The type that we devised in the example ("Drawable") is an abstract type. We cannot directly construct or use a Drawable. However we can construct and use "real" object type that satisfies (meets) the Drawable idea. These might include:
Arc, Line, Fractal, Ellipse, Rectangle, ... (unlimited)
📋
Abstract: An idea. A concept. Describes operations (methods) that can be performed. Not a "real" thing. Not operationally usable. (e.g. Drawable)Concrete: An actual thing. Reality. Yes is operationally usable. (e.g. Arc, Line, Fractal, Ellipse, Rectangle)
Example Abstractions
Here are a couple examples showing the usefulness of abstractions.
C++
In C++ we might have a header file showing something like this:
//Returns cosine of angle x in radians.
double cos (double x);
📋
//Returns the base raised to power exponent
double pow (double base, double exponent);
📋
The details of these calcs are abstracted (hidden), but as coders, this gives us enough info to use:
cout<< cos (PI/2.0);
cout<<10^2 = << pow(10,2);
📋
Java
We don't know all details inside the Java library (they are effectively abstracted/hidden), but we can easily glance
at "Method Summaries" like these:
String, https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html
List, https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html
Even without the details this gives us plenty of information to use the objects and methods:
System.out.println("isBlank: " + aString.isBlank());
📋
Recap
Abstraction is a concept that allows us to come up with ideas for objects (what they are) without worrying about the details of how to do them (leave for later/others).
Abstract
If we have a car and only drive it but don't work on the engine or know about the engine then the engine is abstract.
We have an engine but the details (the engine complexity) is effectively "hidden". We don't worry about "how it works" We just know it as an "idea" We know it does work
Concrete
If we have a car and work on the engine we need to know the details.
We have an engine and must know the details (the engine complexity). We do worry about "how it works"
Navigation
Data Structures And Algorithms (DSA)
(Chapter 201 - Generalization and Abstraction)