The meaning of abstraction and implementation in computer science

Click For Summary
Abstraction in computer science simplifies complex systems by encapsulating their components into distinct "black boxes," allowing users to interact with these components without needing to understand their internal workings. This separation enhances modularity, enabling developers to work independently on different parts of a program without interference. For instance, a program that processes data can utilize functions like read_in, process, and write_out, where each function handles a specific task. This structure allows for easy updates and changes without affecting other parts of the program. Additionally, abstraction extends to data representation, such as modeling a car's attributes and behaviors, allowing for inheritance and the creation of specialized classes without redundant code. Overall, abstraction streamlines development and enhances code maintainability.
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · 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