Question

In: Computer Science

Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....

Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?

Solutions

Expert Solution

Abstraction:-
Show/provide necessary functions to the user and hiding the internal implementation of the functions.
There are 2 kinds of abstraction in programming languages:-
1) Procedural abstraction
2) Data abstraction.

1) procedural abstraction :- It is a mental model of what we want a subprogram to do (but not how to do it).

2) Data abstraction:-

A data abstraction is a mental model of what should be done to the collection of data.
We implement the data abstraction by 2 steps:-
2.1) choosing an appropriate data structure - a specific construction of data
2.2) providing appropriate operations (algorithms) to manipulate that data

Implementation of ADT:-
Implementing an ADT means providing a procedure or function for each abstract operation.
Example:- An abstract stack data type can be implemented by the linked list or by an array.
difference between ADT and data structure:-
ADT (Abstract Data Type) is of a logical description, while a Data Structure is concrete.
Examples of data structures:-
Arrays,Stacks,Queues,Linked Lists,Trees,Graphs,Tries,Hash Tables.

Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by the set of values and the set of operations.
ADT gives an implementation-independent view.
The process of providing only the essentials and hiding the internal details(implementation) is known as abstraction.
We can think of ADT as a black box because it shows the external operation but doesn´t show the internal structure.
Examples of ADT:-
1) Container
2) List
3) Set
4) Multiset
5) Map
6) Multimap
7) Graph
8) Tree
9) Stack
10) Queue
11) Priority queue
12) Double-ended queue
13) Double-ended priority queue
Lets take some of the abstract data types and explain in this way:-
1) List ADT
2) Stack ADT
3) Queue ADT

1) List ADT:-

List contains elements of the same type arranged in sequential order.
operations in list:-
1) get() :- Return an element from the list in any given position.
2) insert() :- Insert an element at any position of the list.
3) remove() :- Remove the first occurrence of any element from a non-empty list.
4) removeAt() :- Remove the element at a specified location from a non-empty list.
5) replace() :- Replace an element at any position by another element.
6) size() :- Return the number of elements in the list.
7) isEmpty() :- Return true if the list is empty, otherwise return false.
8) isFull() :- Return true if the list is full, otherwise return false.

2) Stack ADT:-
A Stack contains elements of the same type arranged in sequential order.It follows LIFO (last in first out) order.
operations:-
1) Push()
2) pop()
3)Peek()
4) Size()
5)isEmpty()
6) isFull()

3) Queue ADT:-

It contains elements of the same type that are arranged in the sequential order.
Operations take place at both ends, insertion is done at the end and deletion is done at the front in the queue.

operations:-
1) enqueue()
2) dequeue()
3) peek()
4) size()
5) isEmpty()
6) isFull()

Advantages of abstract data typing:-
1) Encapsulation
2) No editing of code object that uses ADT
3) Flexibility

We use the abstraction concept in object-oriented programming and as well as to classes.We can use the abstraction concept in data structures also.Because lets take an example

In stack data type: some operations to be shown to the user such as push,pop,peek,isempty,isnull.The programmer write the internal code of that functions and don´t need to show the user.Only the user is used the functions of the stack.In this way,we can use abstraction in the data structures.



Related Solutions

What are the object oriented concepts and which all object oriented concepts are used in the...
What are the object oriented concepts and which all object oriented concepts are used in the given program? Consider the following code and explain how each of the object oriented concepts are applied in the given program. (CO1) class Vehicle { string brand; public: void honk(); void honk(int); }; void Vehicle::honk() { cout << "Tuut, tuut! \n" ; } void Vehicle::honk(int x) { for(int i=0;i<x;i++) cout << "Tuut, tuut! \n" ; } int main() { Vehicle V1; V1.honk(); V1.honk(3); }
Explain what classes and objects are in object - oriented programming. Give an example of each...
Explain what classes and objects are in object - oriented programming. Give an example of each and explain how they work together in a computer program.
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction...
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction Class Object Method Message Passing
Using the various Object Oriented Programming concepts and skills learnt in this course, design and develop...
Using the various Object Oriented Programming concepts and skills learnt in this course, design and develop a Java Application to compute an individual student’s GPA and store the records in a database. The application should have two components i.e. The student and the course components. The following should be the minimal operations on the course component: – Set course information – Print course information – Show credit hours – Show course number The following should be the minimal operations on...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with...
What is different between procedural and object-oriented programming? Match each of the following OOP concepts with its example/description. Question 2 options: 12345678 Providing a way for an entity to behave in several ways OR providing multiple entities to be treated in a similar way 12345678 A key way of saving having to retype a lot of code for similar but different objects 12345678 The removal of non-essential information 12345678 Allowing which function to be called by an object to be...
C++In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must...
C++In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must quickly...
In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
Briefly explain the terms used in object-oriented programming with examples.
Briefly explain the terms used in object-oriented programming with examples.
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT