TN Online TestSamacheer Kalvi practice

Data Abstraction - Study Notes

Share this chapter: Telegram

Chapter Summary

Data abstraction is a foundational programming design pattern that enables developers to manage complex software systems by hiding implementation details and presenting a simplified interface. By segregating code into an abstract interface and a concrete representation, developers can write robust, modular programs that can be updated independently. This methodology relies heavily on constructors to assemble abstract objects and selectors to fetch their properties, establishing a solid barrier between how data is used and how it is stored.

Learning Objectives

Key Concepts and Definitions

Abstract Data Type (ADT)

An Abstract Data Type is a high-level model for data structures where the behavior of the data is defined by a set of values and operations, completely independent of any physical implementation in memory.

Constructor

A constructor is a specialized function responsible for creating and initializing a new instance of an abstract data type, bundling its constituent data parts together.

Selector

A selector is a function designed to query an abstract data type and retrieve specific, individual components of its internal information.

Concrete Data Type

A concrete data type is a representation whose exact structure and memory layout are fully known and directly accessible within the code.

Pair

A pair is a basic compound data construct that groups two values together. It forms the foundational building block for constructing more elaborate abstract data structures.

Worked Methods

Implementing a Rational Number ADT

To manipulate fractions precisely without losing accuracy through floating-point division, we can construct a Rational Number ADT. We design this using the strategy of wishful thinking: we assume constructors and selectors exist before writing their actual code.

First, we define our constructor rational(n, d) which binds the numerator and denominator together. Next, we declare two selectors: numer(x) to fetch the numerator and denom(x) to fetch the denominator.

Using these abstract operations, we can write a function to multiply two rational numbers without knowing how they are represented internally:

multiply_rational(r1, r2) is computed as: the numerator of the result is numer(r1) multiplied by numer(r2), and the denominator is denom(r1) multiplied by denom(r2). The final result is returned by passing these into the rational() constructor. This maintains a perfect abstraction barrier.

Common Exam Traps

Exam Tips

Solved MCQs → Practice test →

More for this chapter

Book Back Questions10 textbook MCQs · solved Additional MCQs15 extra MCQs · solved Practice TestInteractive · instant score Book Back TestTest yourself on the textbook set Additional MCQ TestTest yourself on the extra set Formula SheetAll key formulas

More chapters in Computer Science

View all
1 Function 3 Scoping 4 Algorithmic Strategies 5 Python -Variables and Operators 6 Control Structures 7 Python functions 8 Strings and String manipulation 9 Lists, Tuples, Sets and Dictionary 10 Python Classes and objects 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV files 14 Importing C++ programs in Python. 15 Data manipulation through SQL 16 Data visualization using pyplot: line chart, pie chart and bar chart