chap07 - Chapter 7 Chapter The The Class Construct and OOD and Key Concepts Key class construct information hiding encapsulation data members member

chap07 - Chapter 7 Chapter The The Class Construct and OOD...

This preview shows page 1 - 14 out of 43 pages.

Image of page 1
Chapter 7 : Chapter 7 : The The Class Construct Class Construct and OOD and OOD
Image of page 2
Key Concepts: Key Concepts: class construct information hiding encapsulation data members member functions constructors inspectors mutators facilitators destructor const functions access specification public private object-oriented analysis object-oriented design
Image of page 3
Usage of Class: Defining objects Defining objects with attributes with attributes and behavior and behavior
Image of page 4
Class Types Class Types Class construct Allows programmers to define new data types for representing information Class type objects can have both attribute components and behavior components Provides the object-oriented programming in C++ Example we shall consider is RectangleShape of ezWindow library
Image of page 5
Terminology Terminology Client Program using a class Object behaviors Realized in C++ via member functions (methods) RectangleShapes can be drawn or resized Object attributes Are known as data members in C++ RectangleShapes have width, height, position, color
Image of page 6
The declaration of class class ClassName { public: // Prototypes for constructors // and public member functions // and declarations for public // data member go here ... ... private: // Prototypes for private // member functions and // declarations for private // data member go here ... ... } Class keyword Public keyword Private keyword A valid C++ name
Image of page 7
class RectangleShape { public: RectangleShape(SimpleWindow &Window, float fXCoord, float fYCoord, const color &Color, float fWidth , float fHeight); void Draw(); color GetColor() const ; float GetWidth() const ; float GetHeight() const ; void GetSize( float &fWidth, float &fHeight) const ; void GetPosition( float &fXCoord, float &fYCoord) const ; SimpleWindow& GetWindow() const ; void SetColor( const color &Color); void SetPosition( float fXCoord, float fYCoord); void SetSize( float fWidth, float fHeight); private: SimpleWindow &Window; color m_emColor; float m_fXCenter; float m_fYCenter; float m_fWidth; float m_fHeight; } The declaration of class The declaration of class
Image of page 8
Image of page 9
Member Functions The behavior The behavior of object of object Provide a controlled interface to data members and object access and manipulation Create objects of the class Inspect, mutate, and manipulate object of the class Can be used to keep data members in a correct state
Image of page 10
Member Functions Send a message to objects by invoking a member function through object Identifier.Message([Arg 1 , Arg 2 , … Arg N ]); Object Name Message Type (Member Function) Member Access Operator Optional Argument List (Message Contents) R.SetSize(3, 5); R.SetColor(Red); R.Draw();
Image of page 11
Member Functions Constructors Member functions that initialize an object and allocate resources for the object during its definition Constructor’s name is always same as the name of class Constructors do not have a type A class can have multi-constructor Constructors are automatically invocated when the object is defined Example RectangleShape(SimpleWindow &Window, float fXCoord, float fYCoord, const color &Color, float fWidth , float fHeight);
Image of page 12
Member Functions Inspectors Member functions that act as a messenger that returns the
Image of page 13
Image of page 14

You've reached the end of your free preview.

Want to read all 43 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes