What is Abstraction

10

One of the Big Ideas in Computer Science is abstraction. As we will see, abstraction is an important concept and practice in computer science. But what exactly is abstraction?

Technical Terminology

  • abstraction - An abstraction is a general representation of something: of some person or place or event or process. An abstraction extracts common features from specific examples in order to generalize concepts. Words, symbols, maps, and models are all examples of everyday abstractions
    • abstraction in computer programming - a procedure that is called many times
  • abstracting - Abstracting is the process of creating abstractions
  • constant - A constant, such as the numeral '5', is an abstraction that represents a single thing, e.g., the value 5
  • variable - A variable, such as the symbol 'X', can be used to represent any number and is therefore more general and more abstract than a constant
  • data abstraction - Data abstraction in computer science is the practice of organizing and encapsulating certain data into a more general representation. An example would be storing the text 'hello' in a single variable rather than having numerous occurrences of 'hello' in a program
  • procedural abstraction - Procedural abstraction in computer science is the practice of organizing and encapsulating algorithms in named procedures that can then be invoked (called) by name. An example would be the 'sqrt(x)', square root of x, which encapsulates the algorithm for calculating the square root of x

Procedures

View this slide show explaining the basics of procedures and some advanced features that procedures can utilize.

You can think of Procedures as shortcuts in your code.

Instead of having all your code repeated all over the place, we put the code in one procedure and instead use lots of calls that reference this procedure wherever we want the code to run (execute).

Procedure

← Video


Slides →

01.08 What is Abstraction

Two Types of Abstraction

In computer science there are two main types of abstraction: Data Abstraction and Procedural Abstraction.

Data Abstraction is the use of variables that represent numbers, words, colors, or objects with specific properties to be stored.

Procedural Abstraction is a mental model of what we want a subprogram to do. For example, if you wanted to compute the length of the a hypotenuse of a right triangle, you would first create a subprogram (or procedure) that gets sides A and B as inputs from a user, does the math algorithm, and returns side C as the result. To use procedural abstraction the user would simply call it by writing the name of the procedure, for example: hypotenuse( 3, 4);