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.
#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.
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
rorix_bw
145
0
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
rorix_bw
145
0
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.
i am a cse student and as a second year student i started building apps. by sing chatgpt i am getting frontend files and backend files but i fail to connect those files. how to learn it and when i asked my friend he said learn about api keys. should i learn that or learn something new
I've tried to intuit public key encryption but never quite managed.
But this seems to wrap it up in a bow.
This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher.
Is this how PKE works?
No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...