Data Abstraction & Problem Solving with C++, 6th Edition
Throughout this book we design abstract data types and implement them as data structures using C++. This C++ Interlude provides a refresher on C++ classes and then introduces additional C++ tools we can use to defi ne our abstract data types in a flexible manner that maintains the wall between our design and the implementation.
After reviewing classes, we will look at class templates . This C++ construct gives us the power to specify the data type of the items contained in a data structure in a very generic way. For example, if you had spent two weeks developing a great class to represent a bag of integers, wouldn’t it be great if you could easily use the same code for a bag that holds strings? Class templates allow you to defi ne classes that are independent of the type of data stored in the data structure. When a client is ready to instantiate an object of the class, the client can specify the type of data the object holds.
Header ( .h ), or specifi cation , files in C++ provide a mechanism to partially separate the design of a class from the implementation in the source , or implementation ( .cpp ), file . The header file must also contain a description of both the data fields for the class and any private methods used by the class. A client does not need to know about the private methods or data fi elds to use the class in a program. To provide a public interface for an ADT, you can write an abstract base class, there by separating design from implementation. An abstract base class allows the client to take full advantage of polymorphism when using our class. To introduce these concepts, let’s look at a simple problem that illustrates all three of the fundamental concepts of object-oriented programming: encapsulation, inheritance, and polymorphism.
|Download Ebook||Read Now||File Type||Upload Date|
||Read Now||February 19, 2015|
Do you like this book? Please share with your friends, let's read it !! :)How to Read and Open File Type for PC ?