Properties and Purpose of ADTs in Programming
Core Principles of ADTs
Abstraction
Focus on What, Not How: ADTs define what operations can be performed, not how they are implemented.
ExampleA queue ADT allows operations like enqueue and dequeue without revealing the underlying data structure (e.g., array or linked list).
Exam techniqueIn answers, always phrase ADTs in terms of operations (what you can do) rather than implementation (how it’s done).For full marks, give an example:
e.g., “A queue supports enqueue and dequeue operations, regardless of whether it is implemented with an array or linked list.”
Encapsulation
Data Protection: ADTs encapsulate data, ensuring it can only be accessed or modified through defined operations.
ExampleA stack ADT only allows push and pop operations, preventing direct manipulation of its elements.
NoteEncapsulation is a key principle of object-oriented programming, where ADTs often serve as the foundation for classes and objects.
Modularity
Interchangeable Implementations: ADTs promote modularity by hiding implementation details, allowing different implementations to be swapped without affecting the rest of the program.
ExampleA list ADT can be implemented using an array or a linked list, and the choice can be changed without altering the code that uses the list.
Tip- When designing a system, start by defining the ADTs you need.
- This helps you focus on the problem domain rather than getting bogged down in implementation details.
Reusability
High-Level Design: The abstract nature of ADTs makes them reusable across different programs and projects.
ExampleA set ADT can be used in various contexts, such as managing unique user IDs or tracking visited nodes in a graph.