COMP1006/1406 Abstraction
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
COMP1006/1406
Abstraction
In software engineering and computer science, abstraction is
a technique for managing complexity of computer systems. It
works by establishing a level of complexity on which a person
interacts with the system, suppressing the more complex details
below the current level.
-wikipedia
Java
↑
assembly language
↑
machine language
↑
hardware
Abstraction
One of the first computers, the ENIAC computer
Abstraction
The first actual computer programmers were mostly women
Abstraction
Early way of recording your program was using Punch Cards
Abstraction
Assembly language introduced short ‘words’ for operations and memory
locations
First assembly language developed in 1947 by Kathleen Booth
Abstraction
High level languages look more like human language than machine
language
Grace Hopper developed the first compiler in 1952
(converting human words into machine code)
Abstraction
A first step in abstraction for us in COMP1405/1005 was the use of
variables.
Recall that a variable is a name that maps to a memory location in our
programs. Without variables, we would have to manually place data into
memory locations and remember what data was placed where. If you are
programming in machine language or assembly, you still need to do this.
A well named variable makes our programs easier to read, write and
debug. It takes away the burden of managing our data at such a low level.
Abstraction
A next step in abstraction for us is the notion of a procedure (which has
many different names)
· procedure
· function
· method
· subroutine
A procedure is a sequence of instructions (statements) that performs a
specific task.
Math.sin(0.172) computes the sine of 0.172 radians. We don’t really
care how it does it, we just care that it gives us the right value.
System.out.println("hi") prints the characters h and i to the screen.
How does this actually happen? Do we care how it happens?
Abstraction
A next step in abstraction for us is the notion of a procedure (which has
many different names)
· procedure
· function
· method
· subroutine
A procedure is a sequence of instructions (statements) that performs a
specific task.
Math.sin(0.172) computes the sine of 0.172 radians. We don’t really
care how it does it, we just care that it gives us the right value.
System.out.println("hi") prints the characters h and i to the screen.
How does this actually happen? Do we care how it happens?
Procedural programming
In COMP 1005/1405, you practised procedural programming. It is a
form of structured programming that helps make programming
(writing/reading/modifying code) easier for humans.
· program is a sequence of procedure (function) calls
· code that does one thing is grouped into a procedure
· helps us achieve modularization
· code that is repeated during the execution of the program is put in a
procedure
· lets us write less code (less testing and maintenance!)
· helps us write structured programs
· this helps us write better programs (Software Engineering)
We can write procedural programs in Java.
Procedural programming
public class MenuDrivenProgram{
public static void main(String[] args){
boolean programRunning = true;
String input = "";
while (programRunning){
displayMenu();
input = getUserInput();
programRunning = processInput(input);
}
}
}
Procedures (functions)
· should have meaningful names
(intention of function should be clear from name)
· should do one thing (and do it well)
· typically do not contain a lot of code
Procedural programming
In Java, procedural programming might involve writing and using a
collection of static functions
You will most likely still use objects when writing code in this style in
Java. Otherwise, we could only use primitive data types which may be
limiting.
In Particular,
· arrays are objects
· strings are objects
· many useful functions belong to objects of a given class (like println)
Abstraction
We will see other forms abstraction in this course.
· classes/objects
· inheritance
· polymorphism
2026-01-23