Abstraction: The removal of layers of detail to simplify a viewpoint.
Encapsulation: The bundling together of methods and data that are used together. Enables data to
be hidden as ‘private’ data types and only accessed through public methods. This a fundamental
principle of OOP and is very useful in
Abstract data types are data structures and types that do not exist as an intrinsic data type or
structure in a language. They must be created by the programmer using other data types and certain
functions to ensure their use.
Most ADTs utilise abstraction to make it easier for the user to use them. An ADT may be provided in
a library in such a way that the user knows how to use the ADT in their code, but not exactly how
they were implemented in the first place. They have an abstracted view of the ADT. This may be
achieved by encapsulating the necessary data and methods in a class.
An example of an ADT is a queue. A queue is a static data structure that may be circular and
operates on a First in, First out basis (FIFO). Data is added to the ‘rear’ and removed from the ‘front’,
both of which are kept track of with pointers. A queue should also be present with the enqueue(),
dequeue() and peek() methods to add and remove data, as well as check what item is at the front of
the queue. There should also be an isEmpty() method to check whether the queue is empty and
size() method to check its size.
Arrays
Arrays aren’t an abstract data type, but they are one of the data types upon which many ADTs can
be built. In some languages, such as Java, the compiler will throw an error if one tries to access
indexes outside the bounds of the array. Others, like C, will not do this and will simply return the
value that happens to be in that index in memory, even though it is not in the array.
Different languages provide different means to loop through arrays. Some languages simply index all
arrays starting from 0. Others let the programmer specify the upper and lower bounds of the array
so that they can be looped though more easily, i.e. position 1 might have an index 18, instead of 0.
Some languages also allow the programmer to use other discrete values, such as characters, as
indexes for and array.