The meaning of abstraction and implementation in computer science

Click For Summary

Discussion Overview

The discussion revolves around the concepts of abstraction and implementation in computer science, with a focus on providing simpler definitions and examples. Participants explore the implications of these concepts in programming and software design.

Discussion Character

  • Conceptual clarification
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant requests simpler definitions of abstraction and implementation, indicating that existing definitions are too technical.
  • Another participant suggests sharing found definitions to facilitate a clearer discussion.
  • A third participant provides a generic explanation of abstraction, describing it as encapsulating system parts into "black boxes" that allow usage without knowledge of internal workings.
  • This participant illustrates abstraction with a programming example, contrasting a direct file processing approach with a more abstracted function-based approach.
  • The example emphasizes the importance of defining APIs for functions to allow developers to work independently without interfering with each other's code.
  • Abstraction is also discussed in the context of data representation, using the example of a car's properties and the concept of inheritance in programming.
  • A later reply mentions an interest in design patterns related to abstraction, noting that the initial example provided is a simplistic illustration of the concept.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and interpretation of abstraction, with no consensus on a single definition or approach. The discussion remains exploratory and open-ended.

Contextual Notes

The discussion includes assumptions about the audience's familiarity with programming concepts and lacks specific definitions that could clarify the terms further. The examples provided may not cover all aspects of abstraction and implementation.

blacksmith
Messages
3
Reaction score
0
Hello, I was wondering if someone could give me a "for dummies" definition of abstraction and implementation in computer science? The online definitions are very technical and I can't quite wrap my mind around them.
 
Technology news on Phys.org
How about you provide us with the definitions you've found, and then we can do our best to translate them into more basic terms.
 
The question is ill-defined so my answer will be very generic.

In its simplest form abstraction is encapsulating the parts of a system into separate little black boxes. This allows people to use them without requiring knowledge of how they work, or their internals, and prevents one part of the program from adversely affecting another.

This is done in a number of ways.

Say you want to write a program that reads in data from a file, and applies a function to said data, then prints it.

You do could do it like this (code is Python unless otherwise specified):

Code:
if = open ("data.txt", "r")  # open input file
of = open ("data2.txt", "w") # open output file
for line in f.readlines():   # for each line ...
    line.strip ()            # stupid trailing LF
    line.reverse ()          # reverse it
    of.write (line + "\n")   # save it in output

But that would suck. To use abstraction.

Code:
data = read_in (filename)
data = process (data)
write_out (filename, data)

Much easier with magic black boxes!

How are they defined? Probably like this:

Code:
def read_in (filename):
    f = open (filename, "r")
    return f.readlines ()

def process (d):
    for i in d:
        i.reverse ()
    return i

def write_out (filename, d):
    f = open (filename, "w")
    for i in d:
        f.write (d + "\n")

So long as the API (interface) between the functions is defined, each developer can work away in private on his/her function without stepping on the others' toes (if nothing goes wrong). The developer of process () doesn't need to know or care how the data is read in. All he needs to know is that he receives a list of data in a particular format, he performs the business logic on it, then he returns the modified version in a particular format. If something changes like the method of reading the data, it's similarly easy to redo becuase of the separation of functions.

When you include a module e.g.
Code:
import math
You are again using abstraction.

Abstraction is also used to represent data.

Code:
# not code, had to use code tags for formatting!
car
- engine
  - size, horsepower
- controls
  - steer, start, stop etc
- payload
  - number of passengers, max weight possible

We can rapidly swap engines from another car, etc

Code:
# "copy" engine and all its contained properties (size, HP, status etc)
red_car.engine = blue_car.engine

I put "copy" in quotes because Python doesn't [STRIKE]always[/STRIKE] copy here, but the result will be the same data in both car engines.

We can also use the concept of inheritance to derive a more specalised car from the base car

convertible_car
- derived from car
- exactly the same but adds new features: roof up, roof down, get roof state

Then you no longer need separate code to process each car

Code:
for this_car in list_of_cars:
    this_car.start_up () # we start ANY car like this
    try:
        this_car.roof_up ()
    except:
        print ("This car can't do that")

So you don't need to write separate code for each type of car.
 
Last edited:
I'd like to get into design patterns (usin abstraction for program structure) but that's kind of long. In any case the first example (text processor) is a very crude exmaple of this.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
5K