13. Abstract Data Types#
A client needs to know what a collection promises before it needs to know where the values live. This chapter connects abstract data type contracts to representations, invariants, generics, iteration, and operation costs. These ideas provide the vocabulary for comparing the concrete structures in the following chapters.
Abstract data type: An ADT specifies values and operations separately from implementation details.
Interface: An interface names the operations a type promises to provide.
Representation: The same behavior can be backed by arrays, linked nodes, or other internal structures.
Reference: References let objects connect to other objects and share state through identity.
Generic type: Generics let one ADT implementation work with many element types safely.
Chapter Video
Master C# Interfaces in 12 Minutes - Beginner Tutorial (11:36) by tutorialsEU - C#.
Hosted on YouTube; property of its original creator, embedded here for educational reference only.
Learning Objectives
By the end of this chapter, you will be able to:
Define an abstract data type by its values and operations.
Distinguish an interface from an implementation.
Trace references and object state in memory diagrams.
Use generics to write reusable collection-style code.
Explain input size, Big-O growth, amortized operations, and auxiliary space.
Compare basic operation costs for common collection representations.
Implement
IEnumerable<T>usingyield returnso a custom type supportsforeach.
Chapter Flow
Suggested three-meeting pace (110 minutes): read the relevant explanations and predict the selected example before class.
Meeting |
Minutes |
Guided focus |
|---|---|---|
1 |
35 |
contracts, representation independence, and counted costs. |
2 |
40 |
generic contracts, constraints, and policy arguments. |
3 |
35 |
iterator positions, yield, and deferred enumeration. |
Class uses selected traces, runs, and checks. Use the remaining worked examples and detailed API tables for practice and reference. Supporting readings are selected separately; lab and homework follow the core lessons.
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Abstract data type |
A data type described by its values and operations rather than its implementation. |
2 |
Contract |
The promised behavior an ADT operation provides. |
3 |
Implementation |
The concrete code and representation used to realize an ADT. |
4 |
Representation |
The internal data layout used to store an ADT. |
5 |
Operation |
An action an ADT supports, such as add, remove, or lookup. |
6 |
Invariant |
A rule that must remain true for a representation to be valid. |
7 |
Precondition |
A requirement that must hold before an operation is called. |
8 |
Postcondition |
A result that should hold after an operation completes. |
9 |
Interface |
A named contract that types can implement. |
10 |
Generic |
Reusable code written with type parameters. |
11 |
Type parameter |
A placeholder for a type used by generic code. |
12 |
Cost |
The time or memory needed by an operation. |
13 |
Client code |
Code that uses an ADT through its public operations. |
14 |
Information hiding |
Keeping representation details separate from code that uses the ADT. |
15 |
Iterator |
A method or object that produces a sequence of values one at a time. |
16 |
|
A statement that produces one element of an iterator and pauses until the next is requested. |
17 |
Lazy evaluation |
Computing a value only when it is actually requested, not in advance. |
18 |
Input size |
The number of items or other dimensions used by a cost model. |
19 |
Big-O |
An upper bound on cost growth for sufficiently large inputs. |
20 |
Auxiliary space |
Storage beyond the input used by an operation. |
21 |
Traversal lifetime |
The period during which an enumeration remains active and its source policy applies. |