DOC PREVIEW
Duke CPS 006 - Object oriented programming

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CPS 00613b.1Object oriented programmingz Pre-OOPÊ Programmer's duty to devise and enforce logical groupings of the data types and the functions that operate on them.z OOPÊ Functionality is officially and tightly grouped with the type that it operates on.Ê Code re-useÊ OOP uses "messages" instead of function calls.Ê What is a class?Ê What is an object?CPS 00613b.2Inheritancez Process by which a class obtains the properties of its superclasses (ancestors).z HierarchyÊ Classes are generally structured as a treeÊ Subclasses below – Superclasses abovez OverridingÊ When an object receives a message, it checks its own methods first before consulting its superclass.Ê First matching method found in the hierarchy overrides all methods of the superclass(es)z PolymorphismÊ Many classes will respond to a single messageÊ In a graphics program, many of the classes are likely to implement the method drawSelf().CPS 00613b.3Problem Outlinez Model Employee Performance at Springfield’s Nuclear Power Plant.CPS 00613b.4Worker Typesz 4 worker types: Grunt, Homer, Manager, and Bossz All workers have a blood pressure, which tends to go up with excessive work.z Grunts and Homers keep track of how many years they have until retirement. The closer until retirement, the happier theytend to be.z Managers have underlings they order around--their productivity is based upon that of their underlings.CPS 00613b.5Worker Methodsz All workers respond to three messages: Ê StressÊ ProductivityÊ WorkCPS 00613b.6double stress();z Returns the current stress level of the employee. z Stress can be positive (stressing) or negative (relaxing). Ê For all employees, the underlying stress level is (BloodPressure -50) but it can never go over 200. Ê The stress level of Managers and Bosses is the square of the underlying stress. Ê The stress level of Grunts and Homers is the underlying stress plus the number of years until retirement.CPS 00613b.7double productivity();Returns the current productivity factor of an employee which indicates how much work they can accomplish per hour. The productivities of Grunts and Homers are:Grunt: 1.0 + years-to-retireHomer: 1.0 /(years-to-retire + 0.1)Managers tend to get a lot of useful work out of their underlings, so the productivity of a Manager is the sum of the productivities of that manager's underlings. Bosses tend to mostly scare their underlings to death, so the productivity of a Boss is only the mean average of the productivities of that Boss's underlings.CPS 00613b.8bool work(double amount);z Sent to an employee when that employee has been asked to do work. The method returns true if the work was done, and false otherwise.z Employees refuse work and return false if their Stress level is greater than 100 or the amount of work is > 10 times their productivity.z Passing that, Grunts and Homers just do the work (and their blood pressures are raised by their Productivity).CPS 00613b.9bool work(double amount); (continued)zManagers and Bosses respond by delegating the work to their underlings. Managers ask each underling in turn to do the work until one of the underlings agrees. z At that point, the manager is satisfied and returns true, confident that the work has been done. The manager returns false if no underling will do the work. z Bosses work similarly, but when an underling does the work, there's only a 50% chance that the Boss will be satisfied. If the boss is satisfied, they return true. If the boss is not satisfied, they go ahead and ask more underlings to do the work, even though at least oneunderling has already done it. The Bosses return false if they were never satisfied.CPS 00613b.10Class hierarchyEmployeeWorker ManagerManager Homer Bossindicates abstract ClassCPS 00613b.11Class Outlinesz Employee: Abstract base class. All methods implemented but productivity(), which is abstract. z Worker: Abstract class, extends Employee. Refines stress() and work().z Homer and Grunt: Extends Worker. Implements productivity()z Manager: Extends Employee. Refines stress() and implements productivity()z Boss: Extends Manager. Refines productivity() CPS 00613b.12Problem for examz Define the Employee class, subclasses, and header filesÊ Do you need any more information to successfully create these classes?z How would you create a group of random


View Full Document

Duke CPS 006 - Object oriented programming

Download Object oriented programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object oriented programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object oriented programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?