| New Reply |
The meaning of abstraction and implementation in computer science |
Share Thread | Thread Tools |
| Jul16-12, 11:08 AM | #1 |
|
|
The meaning of abstraction and implementation in computer science
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.
|
| Jul16-12, 08:26 PM | #2 |
|
Mentor
|
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.
|
| Jul22-12, 12:31 AM | #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
Code:
data = read_in (filename) data = process (data) write_out (filename, data) 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")
When you include a module e.g. Code:
import math 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 Code:
# "copy" engine and all its contained properties (size, HP, status etc) red_car.engine = blue_car.engine 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")
|
| Jul22-12, 12:39 AM | #4 |
|
|
The meaning of abstraction and implementation in computer science
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.
|
| New Reply |
| Thread Tools | |
Similar Threads for: The meaning of abstraction and implementation in computer science
|
||||
| Thread | Forum | Replies | ||
| Similarities / Differences between Computer Science and Computational Science | Academic Guidance | 2 | ||
| Computer Engineering vs Computer Science ?? | Academic Guidance | 4 | ||
| Computer science or computer science with mathematics? | Career Guidance | 4 | ||
| Computer Science VS Computer Engineering (Academic Research....? Similar?) | Academic Guidance | 3 | ||
| No computer science at the computer science forum! | Forum Feedback & Announcements | 8 | ||