abstract data type

 

ABSTRACT DATA TYPE


What is abstract data type?

An abstract data type is an abstraction of a data structure that provides only the interface to which the data structure must adhere. The interface does not give any specific details about something should be implemented or in what programming language.

In other words, we can say that abstract data types are the entities that are definitions of data and operations but do not have implementation details. In this case, we know the data that we are storing and the operations that can be performed on the data, but we don't know about the implementation details. The reason for not having implementation details is that every programming language has a different implementation strategy for example; a C data structure is implemented using structures while a C++ data structure is implemented using objects and classes.

For example, a List is an abstract data type that is implemented using a dynamic array and linked list. A queue is implemented using linked list-based queue, array-based queue, and stack-based queue. A Map is implemented using Tree map, hash map, or hash table.

Abstract data type model

Before knowing about the abstract data type model, we should know about abstraction and encapsulation.

Abstraction: It is a technique of hiding the internal details from the user and only showing the necessary details to the user.

Encapsulation: It is a technique of combining the data and the member function in a single unit is known as encapsulation.



The above figure shows the ADT model. There are two types of models in the ADT model, i.e., the public function and the private function. The ADT model also contains the data structures that we are using in a program. In this model, first encapsulation is performed, i.e., all the data is wrapped in a single unit, i.e., ADT. Then, the abstraction is performed means showing the operations that can be performed on the data structure and what are the data structures that we are using in a program.

Let's understand the abstract data type with a real-world example.

If we consider the smartphone. We look at the high specifications of the smartphone, such as:

  • 4 GB RAM
  • Snapdragon 2.2ghz processor
  • 5 inch LCD screen
  • Dual camera
  • Android 8.0

The above specifications of the smartphone are the data, and we can also perform the following operations on the smartphone:

  • call(): We can call through the smartphone.
  • text(): We can text a message.
  • photo(): We can click a photo.
  • video(): We can also make a video.

The smartphone is an entity whose data or specifications and operations are given above. The abstract/logical view and operations are the abstract or logical views of a smartphone.

The implementation view of the above abstract/logical view is given below:

  1. class Smartphone  
  2. {  
  3.    private:  
  4.    int ramSize;  
  5.    string processorName;  
  6.    float screenSize;  
  7.    int cameraCount;  
  8.    string androidVersion;  
  9.    public:  
  10.      void call();  
  11.      void text();  
  12.      void photo();  
  13.      void video();  
  14. }   

The above code is the implementation of the specifications and operations that can be performed on the smartphone. The implementation view can differ because the syntax of programming languages is different, but the abstract/logical view of the data structure would remain the same. Therefore, we can say that the abstract/logical view is independent of the implementation view.


No comments:

Post a Comment