|
||
| Lesson 3
Objective
|
Type extensibility
Usefulness of adding user-defined types to C++ |
|
|
Type extensibility is the ability to add user-defined types to C++ so the new types are as easy to use as native types.
An Abstract Data Type (ADT) is an extension to the native types available in C++. It consists of a set of values and a collection of operations that can act on those values. An ADT is a description of the ideal public behavior of the type. Example of a simple ADT string. The user of a string knows that operations, such as concatenate or print, result in certain public behavior. A concrete implementation of the ADT also has implementation limits, for example, strings might be limited in size. These limits affect public behavior. Also, internal or private details of the implementation do not directly affect the user's understanding. For example, a string is frequently implemented as an array. The internal base address of this array and its name should be of no direct consequence to the user. If we want to create a string type that differs from the string type already available in C++, we can easily do so. For example, we could create a variation on the string type that has a certain length limit and has the ability to print itself out backwards and capitalize every other letter. |
||
|
|
||