tailieunhanh - Chapter 7 - Classes Part II
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 Introduction const (Constant) Objects and const Member Functions Composition: Objects as Members of Classes friend Functions and friend Classes Using the this Pointer Dynamic Memory Management with Operators new and delete static Class Members Data Abstraction and Information Hiding Example: Array Abstract Data Type Example: String Abstract Data Type Example: Queue Abstract Data Type Container Classes and Iterators Proxy Classes Introduction Classes Data abstraction Object-based programming (OBP) Chapters 6-8 Inheritance and polymorphism Chapters 9 and 10 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 . | Chapter 7: Classes Part II Outline Introduction const (Constant) Objects and const Member Functions Composition: Objects as Members of Classes friend Functions and friend Classes Using the this Pointer Dynamic Memory Management with Operators new and delete static Class Members Data Abstraction and Information Hiding Example: Array Abstract Data Type Example: String Abstract Data Type Example: Queue Abstract Data Type Container Classes and Iterators Proxy Classes Introduction Classes Data abstraction Object-based programming (OBP) Chapters 6-8 Inheritance and polymorphism Chapters 9 and 10 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 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 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 (1 of 2) 1 // Fig. : 2 // Definition of class Time. 3 // Member functions defined in . 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 .
đang nạp các trang xem trước