Data Abstraction
Destructors
• Destructors are functions without any type
• The name of a destructor is the character '~' followed by class name
– For example:
~clockType();
• A class can have only one destructor
– The destructor has no parameters
• Destructor automatically executes when the class object goes out of scope
C++ Programming: Program Design Including Data Structures, Sixth Edition
2
Data Abstract, Classes, and Abstract Data Types
• Abstraction
– i.e., we want to know how to start the car and drive it
• No concern about how the engine works
C++ Programming: Program Design Including Data Structures, Sixth Edition
3
Data Abstract, Classes, and Abstract Data Types
• Abstraction
– Separating design details from usage Abstraction
– Separating logical properties from the implementation details
• i.e., driving the car is a logical property; the construction of engine constitutes the implementation details
• Abstraction can also be applied to data
• Abstract data type (ADT): A data type that separates the logical properties from the implementation details
C++ Programming: Program Design Including Data Structures, Sixth Edition
4
Abstract Data Type (ADT)
• ADT has three things associated with it
– Type name (name of the ADT)
– Domain (set of values belonging to the ADT)
– Operations (set of operations on the data)
How to implement an ADT
• Classes are a convenient way to implement an ADT
• In fact, in C++, classes were specifically designed to handle ADTs
Example
• A list is defined as a set of values of the same type
• Therefore, we can use an array for implementation
A struct vs. a class
• By default, members of a struct are public
– private specifier can be used in a struct to make a member private
• By default, the members of a class are private
• classes and structs have the same capabilities
C++ Programming: Program Design Including Data Structures, Sixth