DATA ABSTRACTION Abstract Data Types . Abstract Data type (ADT) is a type for objects whose behavior is defined by a set of values and operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations.
It is called “abstract” because it gives an implementation independent view. The process of providing only the essentials and hiding the details is known as abstraction . You can see that these definitions do not specify how these ADTs will be represented and how the operations will be carried out. There can be different ways to implement an ADT, for example, the List ADT can be implemented using singly linked list or doubly linked list.
Similarly, stack ADT and Queue ADT can be implemented using lists. Data abstraction replicate how we think about the world. For example, when you want to drive a car, you don’t need to know how the engine was built or what kind of material the tires are made of. You just have to know how to diver the car.
To facilitate data abstraction, you will need to create two types of functions: constructors and selectors. 12th Computer Chapter - - constructors and selectors . Constructors are functions that build the abstract data type. Selectors are functions that retrieve information from the data type.
For example, say you have an abstract data type called city. This city object will hold the city’s name, and its latitude and longitude. To create a city object, you’d use a function like city:= makecity (name, lat, lon) To extract the information of a city object, you would use functions like • getname(city) • getlat(city) • getlon(city) The following pseudo code will compute the distance between two city objects: distance(city1, city2): lt1, lg1 := getlat(city1), getlon(city1) lt2, lg2 := getlat(city2), getlon(city2) return ((lt1 - lt2)** + (lg1 - lg2)** )) / In the above code read distance(), getlat() and getlon() as