Examples:
- Words of a spoken language
- Metaphysical abstractions
- Objects in a classroom
- Mathematical abstractions
- Abstraction in programming
Fig: Abstraction in real life
Abstraction in Programming
Data types: An int-type represents an integer, a float-type represents a floating point number
Functions: absoluteValue
double absoluteValue(double d)
{
if(d<0)
{
return -d;
}
else
{
return d;
}
}
#include<cmath>
double absoluteValue(double d)
{
return abs(d);
}
Both of the given example functions do the same thing. We don't need to know how they are doing. So we are focusing on what, not how.
Types of Abstraction
There are two important abstraction techniques:
- control abstraction
- data abstraction
Control abstraction is the separation of the logical properties of an action from its implementation.
Data abstraction is the separation of a data type's logical properties from its implementation.
Reference: wikipedia, artima, microsoft
No comments:
Post a Comment