tailieunhanh - Chapter 11 Separate Compilation and Namespaces
All code goes in some namespace Unless specified global namespace, No need for using directive. Global namespace always available, Implied "automatic" using directive | Chapter 11 Separate Compilation and Namespaces Learning Objectives Separate Compilation Encapsulation reviewed Header and implementation files Namespaces using directives Qualifying names Unnamed namespaces Hiding helping functions Nested namespaces Separate Compilation Program Parts Kept in separate files Compiled separately Linked together before program runs Class definitions Separate from "using" programs Build library of classes Re-used by many different programs Just like predefined libraries Class Separation Class Independence Separate class definition/specification Called "interface" Separate class implementation Place in two files If implementation changes only that file need be changed Class specification need not change "User" programs need not change Encapsulation Reviewed Encapsulation principle: Separate how class is used by programmer from details of class’s implementation "Complete" separation Change to implementation NO impact on any other programs Basic OOP . | Chapter 11 Separate Compilation and Namespaces Learning Objectives Separate Compilation Encapsulation reviewed Header and implementation files Namespaces using directives Qualifying names Unnamed namespaces Hiding helping functions Nested namespaces Separate Compilation Program Parts Kept in separate files Compiled separately Linked together before program runs Class definitions Separate from "using" programs Build library of classes Re-used by many different programs Just like predefined libraries Class Separation Class Independence Separate class definition/specification Called "interface" Separate class implementation Place in two files If implementation changes only that file need be changed Class specification need not change "User" programs need not change Encapsulation Reviewed Encapsulation principle: Separate how class is used by programmer from details of class’s implementation "Complete" separation Change to implementation NO impact on any other programs Basic OOP principle Encapsulation Rules Rules to ensure separation: All member variables should be private Basic class operations should be: Public member functions Friend or ordinary functions Overloaded operators Group class definition and prototypes together Called "interface" for class Make class implementation unavailable to users of class More Class Separation Interface File Contains class definition with function and operator declarations/prototypes Users "see" this Separate compilation unit Implementation File Contains member function definitions Separate compilation unit Class Header Files Class interface always in header file Use .h naming convention Programs that use class will "include" it #include "" Quotes indicate you wrote header Find it in "your" working directory Recall library includes, ., indicate predefined library header file Find it in library directory Class Implementation Files Class implementation in .cpp file Typically give interface file and .
đang nạp các trang xem trước