C++ programming/Chapter 12

From Teknologisk videncenter
< C++ programming
Revision as of 10:15, 16 January 2011 by Heth (talk | contribs)
Jump to: navigation, search

Classes and Abstraction

Knowledge goals

  • To understand the difference between specification and implementation of an abstract data type.
  • To understand the concepts of encapsulation and abstraction.
  • To understand how control and data abstraction facilitate modifiability and reuse.
  • To understand the basic class design principles.
  • To understand how encapsulation and information hiding are enforced by the C++ compiler.

To be able to

  • Declare a C++ class type.
  • Declare class objects, given the declaration of a class type.
  • Write client code that invokes class member functions.
  • Implement class member functions.
  • Organize the code for a C++ class into two files: the specification (.h) file and the implementation file.
  • Write a C++ class constructor.

ADT - Abstract Data Type

An Abstract Data Type is a constructed datatype with its functions. Often gathered in a Class. With Object Oriented Programming it is important to be consequent about the abstraction layers. That will make it easy to understand even very huge and complicated programming projects.

Why ADT

The main purpose of ADT is to hide the implementation details, and allow a user of the implementation to abstract from the inner details of the implementation. The black-box theory. Changes in the implementation will not affect the use of the ADT.

ADT Specification

The Type specification below of TimeOfDay hides the implementation details and lists the

TYPE
TimeOfDay
DOMAIN
Each TimeOfDay value is a time of day in the form of hours, minutes, and seconds.
OPERATIONS
Create a time object.
Print (or write) the time.
Return an object containing the time, incremented by one second.
Compare two times for equality.
Determine if one time is "less than" (comes before) another.