Đang chuẩn bị liên kết để tải về tài liệu:
Chapter 7 - Classes Part II

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Proxy class Hide implementation details of another class Knows only public interface of class being hidden Enables clients to use class’s services without giving access to class’s implementation. Used when class definition only uses pointer to another class Prevents need for including header file | Chapter 7: Classes Part II Outline 7.1 Introduction 7.2 const (Constant) Objects and const Member Functions 7.3 Composition: Objects as Members of Classes 7.4 friend Functions and friend Classes 7.5 Using the this Pointer 7.6 Dynamic Memory Management with Operators new and delete 7.7 static Class Members 7.8 Data Abstraction and Information Hiding 7.8.1 Example: Array Abstract Data Type 7.8.2 Example: String Abstract Data Type 7.8.3 Example: Queue Abstract Data Type 7.9 Container Classes and Iterators 7.10 Proxy Classes 7.1 Introduction Classes Data abstraction Object-based programming (OBP) Chapters 6-8 Inheritance and polymorphism Chapters 9 and 10 7.2 const (Constant) Objects and const Member Functions Principle of least privilege Only allow modification of necessary objects Keyword const Specify object not modifiable Compiler error if attempt to modify const object Example const Time noon( 12, 0, 0 ); Declares const object noon of class Time Initializes to 12 7.2 . | Chapter 7: Classes Part II Outline 7.1 Introduction 7.2 const (Constant) Objects and const Member Functions 7.3 Composition: Objects as Members of Classes 7.4 friend Functions and friend Classes 7.5 Using the this Pointer 7.6 Dynamic Memory Management with Operators new and delete 7.7 static Class Members 7.8 Data Abstraction and Information Hiding 7.8.1 Example: Array Abstract Data Type 7.8.2 Example: String Abstract Data Type 7.8.3 Example: Queue Abstract Data Type 7.9 Container Classes and Iterators 7.10 Proxy Classes 7.1 Introduction Classes Data abstraction Object-based programming (OBP) Chapters 6-8 Inheritance and polymorphism Chapters 9 and 10 7.2 const (Constant) Objects and const Member Functions Principle of least privilege Only allow modification of necessary objects Keyword const Specify object not modifiable Compiler error if attempt to modify const object Example const Time noon( 12, 0, 0 ); Declares const object noon of class Time Initializes to 12 7.2 const (Constant) Objects and const Member Functions const member functions Member functions for const objects must also be const Cannot modify object Specify const in both prototype and definition Prototype After parameter list Definition Before beginning left brace 7.2 const (Constant) Objects and const Member Functions Constructors and destructors Cannot be const Must be able to modify objects Constructor Initializes objects Destructor Performs termination housekeeping time5.h (1 of 2) 1 // Fig. 7.1: time5.h 2 // Definition of class Time. 3 // Member functions defined in time5.cpp. 4 #ifndef TIME5_H 5 #define TIME5_H 6 7 class Time { 8 9 public: 10 Time( int = 0, int = 0, int = 0 ); // default constructor 11 12 // set functions 13 void setTime( int, int, int ); // set time 14 void setHour( int ); // set hour 15 void setMinute( int ); // set minute 16 void setSecond( int ); // set second 17 18 // get functions (normally declared const) 19 int getHour() const; // return hour .