L13_oopcpp

L13_oopcpp - OOP Object Oriented Programming For : COP...

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

View Full Document Right Arrow Icon
1 Object Oriented Programming For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar OOP Object 2 Object 1 Object 4 Object 3 Objects: State (fields), Behavior (member functions), Identity Class : Blue print of an object. Data and behavior are strongly linked in OOP. Objects are responsible for their behavior. Example: Complex numbers, Rational numbers, Floating point numbers , all understand addition. OOP components | Data Abstraction z Information Hiding, ADTs | Encapsulation | Type Extensibility z Operator Overloading | Inheritance z Code Reuse | Polymorphism Recap: ADTs | specify the meaning of the operations independent of any implementation/definition. z Least common denominator of all possible implementations. z Information Hiding: Do not expose unnecessary information. Inheritance | Two example classes | Class Employee class Employee { public: Employee(string theName, float PayRate); string Name() const; float PayRate() const; float compute_pay(float hoursWorked) const; protected: string name; float payrate; }; Inheritance | Two example classes | Class Manager class Manager { public: Manager(string theName, float PayRate); void set_manages(int n); string Name() const; float PayRate() const; float compute_pay(float hoursWorked) const; protected: string name; float payrate; int manages_n_employees; };
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 Reuse | We have done unnecessary work to create Manager, which is similar to (and really is a is a ") Employee. | We can fix this using the OO concept of inheritance . | We let a manager inherit from an employee. z A manager gets all the data and functionality of an employee after inheritance. z We can then add any new data and methods needed for a manager and redefine any methods that differ for a manager. Manager class Manager : public Employee { // is a relationship public: Manager(string theName, float PayRate, int n); void set_manages(int n); protected: int manages_n_employees; }; Methods of Manager have access to name, payrate because they were declared in Employee as "protected” . More on Inheritance :
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.

Page1 / 6

L13_oopcpp - OOP Object Oriented Programming For : COP...

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