Abstraction In Computer Engineering

Today i want to talk about abstraction in computer programming. When you write a paper, you might include a brief summary or abstract to let the potential readers to know if they are interested in reading further. Abstraction in computer science is modelling potential implementations.

These models suppress details while retaining essential features and provide a means for calculating predictions of the models behaviour.

For programmers to be productive, the abstractions that have proved useful for applications need to be available in the languages they use.

We must consider the abstraction both in its relationship to our physical machine. We need to think about abstract machines as well as language paradigms.

There are three types of abstraction supported by programming languages; 

  • Data abstraction ; this consists of a set of objects and a set of operations characterizing their behaviour. 
  • Control abstraction; this is a way of defining a method for sequencing arbitrary actions.
  • Procedural abstraction; this specifies the action of a competition on a set of input objects and the output object produced.

Data abstraction

Data is a raw material for a computer. They are collected facts used as a basis for inference and their computations to be performed on these facts. High-level programming languages look at data according to what can be done to it and with it. For each set of data, certain operations apply either to select out parts or to put parts together.

Data and the store

The store which the collection of data values at a particular moment in the execution of a program is composed of bytes and can be thought of as a series of zeros and ones. The store has a structure since it is organised into bytes, words, blocks, pages, etc. It also is addressed and differentiated between registers, RAM, ROM and user addressable and non addressable sectors.


A value is anything that may be evaluated, stored, incorporated in a data structure or object passed as an argument that is returned etc.

In C the following values exist:

  • Primitive values (int, Char, float, etc)
  • Composite values (int array (30), structures, Unions 
  • Pointers or addresses (Int*,&x,int*functional).


A type is a set of values for example; 

The type integer might correspond to the set {—,-1,0,1,—}

The type must exhibit uniform behaviour under some set of operations e.g addition, multiplication, comparison, etc. Types define entities, properties and behaviour. Programming languages can either be typed or untyped.

Typed languages can be statically typed or dynamically typed. Static typing ensures at compile time that only valid operations are applied to an entity.

In dynamically typed languages, type inconsistencies are not detected until runtime for example; C language.

C++ – statically typed.

Smalltalk – Dynamically typed.

Type examples

Boolean = {false,true}

Integer = {—,-1,0,1,—}

Float = {—,-1,0,1,–,0.0,–1.0,000}

Character = {‘\o’,–,’a’,–,’Z’,–`\255}

Enumerated = {jan,feb,—,dec}

Subrange = {28,29,30,31}

Therefore a type is an abstraction consisting of a type name (name of the type in your program eg; ID number) a type declaration (associates a name with a description; e.g typedef int ID number) and a type description (including a physical description and set of supported operations; e.g integer class).

The cardinality of a set S will be represented as #S. The cardinality is the number of elements in the set:

#Bullion = z 

#Integer = MAXINT -MININT (In Pascal)

#Character =255

#{Jan,Feb,—,dec} =12

# {28,29,30,31}=4

It is also important to note that data representation issues involve;

  • storage management (automatic,static)
  • Scope 
  • Internal versus external representation 
  • Basic types (built into a language e.g, float, int in C)
  • User-defined types (defined using type expressions involving existing types.)

Data independence

The approach to problem solving called stepwise refinement involves two activities. Definition of the program module needed to carry out the various activities involved in the solution and defining data types; including their interaction with the solution activities after the data and its associated operations have been specified and if it becomes necessary to change the representation of the data, nothing else in the program needs to be changed but these operations.

This property is known as data independence. Programs written independently from the final data representations have many advantages, e.g Information hiding which makes a program easier for the user to understand, and also makes programs portable between different languages and machines which make certain security measures practical.

Strong typing

A language is said to be strongly typed if it is not only required that all variables be declared as to type but that these types be strictly enforced at both compile and run time. It is weakly typed if a programmer can declare types but they may be either implicit or not enforced. 

although Pascal is considered to be strongly typed there are certain exceptions. One of these is the variant record. A variant record is considered necessary in many applications primarily to save space. A type that allows its variables to take on values of different types is called a union since the data domain for the type is a union of two or more domains.

Control abstraction

Most programs are constructed to transform or respond to data.


Ordinarily, a program executes sequentially beginning at the first statement and terminating at the last. Branching involves relocating program execution to the portion of our source code different from the succeeding statement. The most common high-level branch statements are the ‘ if – – then –[else]’ and the case statements. The if, provides a two-way and the 2nd a multi-way branch :


If (y==0) x=3;

else x=1;

printf (“%d”,X); /*1 will be printed */ 

 /*the “d” specifies decimal format*/

If (z=y<0)

If (y>0) x=3;

else x=5;

Print f (“%d%d”,z,x);/*0, will be printed*/

In C’s rule, an else belongs with the nearest if that can accept it. Z is assigned the boolean value false (0 in C) since the expression (y<0) is false.

So the statement is

If false


The problem of more ifs than else’s is called the “dangling-else” problem.

To avoid the confusion, Ada has two if statements; one with and one without an else. In either case, the ‘if’ is spaced with an end ‘if’.

This is statement above would be written in Ada; 

if y>0 then

 If y<0 then x:=3;

end if;

end if;

Note that in the Ada fragment, we have not used the expression (Z=y>0) as in the corresponding c statement. Languages where assignments can be made in the context of an expression, are called expression languages. Algol and C are examples.

The case statement depends on a discriminant to select the appropriate case. For example in Ada with discriminant:


The case TODAY is:

when MON.. THUR=>WORK;

when FRI.              = >WORK;


when others           =>null;


In C

Switch (Menu)


Case  1:


Case 2:







Iteration (loops)

By Iteration we mean moving through all the elements of an aggregate in an orderly fashion. Visiting each just once. The simplest iterator is a ‘for’ statement e.g

In Pascal

for i :- 1 to 20 do

sum :- sum + i;

Equivalent in C

For (i =1; i<20; i++);

Sum = sum + i;

The above quote iterates over the integers between 1 and 20, computing their sum. This can also be accomplished by statement that repeats until some terminating condition is encountered e.g

In Pascal 

Sum:= 0; i:= 1 ; delta := 1;

Max:= 20;


Sum := sum + i ; i = i + delta;

          Until i>max;

Or through a statement that tests at the top of the loop rather than the bottom.

An exit controlled loop is written in Pascal as;

sum:= 0; i:= 0; delta := 1 ; max := 20;

While i < max do


i:= i + delta; sum:= sum +i;

The same code in C:

While ( i <max)


i = i + delta;

sum = sum + i;


Iterative and recursive procedures

Iteration may also describe the behaviour of a procedure. In an iterative procedure, statements are executed sequentially even though control may be transferred to another procedure or function.

For such procedures, one enters its environment at the top and exits in exactly one place.

An environment is a collection of variable functions and procedures and their storage locations. In a recursive procedure, one can create many different environments for the same procedure.


An exception occurs when a program execution is interrupted because of an unusual event.

If a program is running in real-time it is particularly important that such events be handled appropriately. the exception is raised when the unusual event occurs and control is transferred to an exception handler.

That is all for today, the next time we shall tackle modularization in programming.