Difference between revisions of "Abstraction"

From CS 61A Wiki
Jump to: navigation, search
[checked revision][checked revision]
m ({{Start-class}})
m (Examples: add real world example)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{Start-class}}
 
{{Start-class}}
'''Abstraction''' is a technique to manage complexity. It is based on ''separation of concerns'': organizing programs so that you can work on one thing at a time in isolation.
+
'''Abstraction''' is a technique for managing complexity. It is based on ''separation of concerns'': organizing programs so that you can work on one thing at a time in isolation. Abstraction hides details that can make a program too complex to understand.
  
 
== Data abstraction ==
 
== Data abstraction ==
Line 9: Line 9:
  
 
== Examples ==
 
== Examples ==
 +
=== Real world ===
 +
Accelerating a car is accomplished by pressing the gas pedal. We don't need to know the specific details of how the gas pedal works (i.e., what is it connected to?); we just need to know what it does.
 +
 
=== Assignment ===
 
=== Assignment ===
 
Assignment binds a name to a value, abstracting away the complexity of the value. Thereafter, the programmer can use the name.
 
Assignment binds a name to a value, abstracting away the complexity of the value. Thereafter, the programmer can use the name.
  
 
=== Function ===
 
=== Function ===
A [[function]] encapsulates a behavior, abstracting away the complexity of its implementation. Only inputs and outputs are important to the programmer.
+
A [[function]] encapsulates a behavior, abstracting away the complexity of its implementation. The programmer can treat the function as a "black box" that spits out a correct result given some inputs.
  
 
== Sources ==
 
== Sources ==
 
* http://inst.eecs.berkeley.edu/~cs61a/sp14/slides/10_6pp.pdf
 
* http://inst.eecs.berkeley.edu/~cs61a/sp14/slides/10_6pp.pdf
 
* http://www.eecs.berkeley.edu/~bh/ssch17/part5.html
 
* http://www.eecs.berkeley.edu/~bh/ssch17/part5.html

Latest revision as of 13:22, 2 July 2014

Abstraction is a technique for managing complexity. It is based on separation of concerns: organizing programs so that you can work on one thing at a time in isolation. Abstraction hides details that can make a program too complex to understand.

Data abstraction

Data abstraction refers to inventing new data types and separating functionality from representation.

Process abstraction

Process abstraction refers to higher-order functions expressing computational processes in a compact form.

Examples

Real world

Accelerating a car is accomplished by pressing the gas pedal. We don't need to know the specific details of how the gas pedal works (i.e., what is it connected to?); we just need to know what it does.

Assignment

Assignment binds a name to a value, abstracting away the complexity of the value. Thereafter, the programmer can use the name.

Function

A function encapsulates a behavior, abstracting away the complexity of its implementation. The programmer can treat the function as a "black box" that spits out a correct result given some inputs.

Sources