Data Abstraction and Encapsulation
- Data Types
(HSM Ch.1.3)
- A data type is a collection of objects and a
set of operations that act on those objects.
- Natural data types
- Simple computer data types (often predefined in a programming
language)
- Aggregate computer data types (often user defined)
- Abstract Data Types
(HSM Ch.1.3)
- Data abstraction separates the specification
of a data type from its implementation.
- An abstract data type is a specification of a collection
of objects and a set of operations that act on those objects.
- Some ADTs
- The Natural Number ADT
(HSM Ch.1.3)
- Natural data types
- Simple computer data types
- Aggregate computer data types
- Benefits of Using ADTs
(HSM Ch.1.3)
- Modularity: each data type can be considered independently.
- Testing: data type implementations can be tested separately
to check that they meet the specifications.
- Division of labour: separate implementation of data types
according to agreed specifications.
- Reusability: implemented data types can be reused.
- Change of implementation: the implementation can be changed
with no effect to users.
- Data Encapsulation
(HSM Ch.1.3)
- Data encapsulation conceals the implementation of a
data type from the user.
- Benefits
- Change of implementation: the implementation can be changed
with no effect to users.
- Prevents corruption: users are not able to manipulate the
data directly, hence incorrectly.
- Data encapsulation is a natural technique when implementing
ADTs, due to the separation of the specification from the
implementation.
Exercises
- ADTs: HSM Ch.1.3, exercises 1-4.
Lab Tasks
Exam Style Questions
- Define {data type,data abstraction,data encapsulation,abstract data type}.
- Give an example of an abstract data type.
- List five benefits of using ADTs, giving a short explanation of each.
- List two benefits of using data encapsulation, giving a short explanation
of each.