The meaning of abstraction and implementation in computer science

In summary, abstraction is encapsulating the parts of a system into separate little black boxes, while implementation is the actual code that does the work.
  • #1
blacksmith
3
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
  • #2
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.
 
  • #3
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:
  • #4
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.
 
  • #5


Sure! Abstraction and implementation are two important concepts in computer science that are used to create efficient and organized computer programs.

Abstraction is the process of simplifying complex systems by focusing on the essential features and ignoring unnecessary details. In other words, it allows us to think about a problem or task in a more general and high-level way, without getting bogged down in the specifics.

On the other hand, implementation refers to the actual coding and building of a program based on the abstract concepts and ideas. It involves translating the abstract ideas into concrete instructions that the computer can understand and execute.

Think of abstraction as the blueprint or plan for a building, while implementation is the actual construction of the building based on that blueprint. Abstraction allows us to conceptualize and plan, while implementation brings that plan to life.

In computer science, abstraction and implementation work hand in hand to create efficient and effective programs. By abstracting away unnecessary details, we can create simpler and more manageable code, making it easier to implement and maintain.
 

1. What is abstraction in computer science?

Abstraction in computer science refers to the process of simplifying complex systems by focusing on the essential elements and hiding unnecessary details. It allows us to represent real-world concepts in a more manageable and understandable way.

2. How is abstraction used in computer programming?

In computer programming, abstraction is used to create abstract data types (ADTs) that encapsulate complex data and operations. This allows programmers to work with high-level concepts rather than low-level implementation details, making code more efficient and maintainable.

3. What is the difference between abstraction and implementation?

Abstraction and implementation are two key concepts in computer science. Abstraction refers to the high-level representation of a system, while implementation is the specific details and code that make up the system. Abstraction focuses on what a system does, while implementation focuses on how it does it.

4. Why is abstraction important in computer science?

Abstraction is important in computer science because it allows us to manage complexity and create more efficient and maintainable systems. It also enables us to create reusable code and design flexible systems that can adapt to changing requirements.

5. Can you give an example of abstraction in computer science?

One example of abstraction in computer science is the concept of classes in object-oriented programming. A class represents a higher-level abstraction of an object, defining its properties and behaviors. This allows programmers to create multiple instances of the class without having to write new code for each one, making code more efficient and maintainable.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
1
Views
826
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
6
Views
963
  • STEM Academic Advising
Replies
3
Views
817
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
5
Views
961
Back
Top