data abstruction

Topics: Object-oriented programming, Class, C++ Pages: 28 (916 words) Published: October 23, 2014
WEEK-3
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 Edition

8

A struct Versus a class
(cont’d.)
• In C++, the definition of a struct was expanded to include member functions, constructors, and destructors
• If all member variables of a class are public and there are no member functions
– Use a struct
• Most programmers restrict their use of structures to adhere to their C-like structure form and thus do not use them to include member functions

C++ Programming: Program Design Including Data Structures, Sixth Edition

9

Information Hiding
• Information hiding: hiding the details of the operations on the data
• Interface (header) file: contains the specification details • File extension is .h

• Implementation file: contains the implementation
details
• File extension is .cpp

• In header file, include function prototypes and comments that briefly describe the functions
– Specify preconditions and/or postconditions
C++ Programming: Program Design Including Data Structures, Sixth Edition

10

Information Hiding (cont’d.)
• Implementation file must include header file via
include statement
• In include statement:
– User-defined header files are enclosed in double quotes
– System-provided header files are enclosed between
angular brackets

C++ Programming: Program Design Including Data Structures, Sixth Edition

11

Information Hiding (cont'd.)
• Precondition: A statement specifying the condition(s) that must be true before the function is called
• Postcondition: A statement specifying what is true after the function call is completed

C++ Programming: Program Design Including Data Structures, Sixth Edition

12

Example (header file)

Example (implementation file)

Example (user program)

For full implementation -> check chapter 11 (clockType)
http://oc.course.com/computerscience/malikdatastructures5e/index.cfm?page=source

Executable Code
• To use an object in a program during execution
– The program must be able to access the implementation
details of...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Webdevelopment Data Grid Dotnet Essay
  • The four V's of Big Data Essay
  • Data Structure Using C++ Essay
  • Data Collection Research Paper
  • What is Data Essay
  • Data Interpretation Essay
  • Big Data Essay
  • Data Security Essay

Become a StudyMode Member

Sign Up - It's Free