L10_classes - Abstraction and Encapsulation Classes II:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Classes II: Type Conversion, Friends, … For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar Abstraction and Encapsulation | Abstraction: Separation of interface from implementation | Encapsulation: Combining lower level elements to form higher-level entity. | Access Labels (public/private/protected) enforce abstraction and encapsulation. Concrete Types. | A concrete class is a class that exposes, rather than hides, its implementation | Example : pair<> (defined in <utility>) | Exists to bundle two data members. | Example: //-- Declare a pair variable. pair<string, int> pr1; //-- Declare and initialize with constructor. pair<string, int> pr2("heaven", 7); cout << pr2.first << "=" << pr2.second << endl; // Prints heaven=7 Benefits of Abstraction & Encapsulation | Class internals are protected from user-lever errors. | Class implementation may evolve over time without requiring change in user-level code. More on Class definitions class Screen { public: private: std::string contents; std::string::size_type cursor; std::string::size_type height,width; Using Typedefs to streamline classes. class Screen { public: typedef std::string::size_type index; private: std::string contents; index cursor; index height,width; } inline Screen::index Screen::get_cursor() const{ return cursor; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Class declaration | class Screen; // declaration of the class | Forward declaration: Introduces the name Screen into the program and indicates that Screen refers to a class name. | Incomplete Type: After declaration, before
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 5

L10_classes - Abstraction and Encapsulation Classes II:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online