object-oriented programming developing an application
TRANSCRIPT
![Page 1: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/1.jpg)
Object-Oriented Programming
Developing an Application
![Page 2: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/2.jpg)
Cooperating Objects and Classes
• Object-oriented software systems consist of interacting objects
• Objects do things by sending messages to each other
• The data and behavior of an object are specified by its class
• A class contains variables for the data and methods for the behavior
![Page 3: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/3.jpg)
Object-Oriented Analysis
• After the user requirements are established, we choose the classes that realize the desired behavior
• Classes may be built-in (String, JButton, etc.) or programmer-defined (Student, Employee, etc.)
![Page 4: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/4.jpg)
Object-Oriented Design
• For each class, we specify the internal data structures and methods
• Within the methods, we show how objects interact to realize the desired behavior (using pseudocode)
![Page 5: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/5.jpg)
Object-Oriented Implementation
• We code the classes, using either a bottom-up, top-down, or mixed approach
• Each class is thoroughly tested individually and then the components are integrated and tested further
• Development usually proceeds incrementally
![Page 6: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/6.jpg)
Example: An Employee Management System
The management wants a system that allows a user to enter each employee’s name, pay rate, and hours worked for each of five days.
Users should be able to browse a list of employees for a given employee’s information.
Users should be able to obtain an employee’s total pay for the week, using time and a half for overtime.
![Page 7: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/7.jpg)
Analysis - Proposed User Interface
![Page 8: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/8.jpg)
Analysis – Develop Prototypes
• A prototype is a trimmed-down or skeletal version of the full system
• A prototype gives the users an idea of what to expect without full functionality
• Might not have all the commands or each one working completely
![Page 9: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/9.jpg)
Analysis – Choose Classes
• We use the model/view pattern
• The model classes manage the data
• The view classes present the data to the user and handle user interaction with the model
![Page 10: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/10.jpg)
The Model Classes
• Employee represents and manages an individual employee’s data
• EmployeeModel represents and manages a list of employees
![Page 11: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/11.jpg)
The View Classes
• EmployeeManagerView displays a list of employee names and the currently selected employee’s information; provides menus for commands
• EmployeeDialog allows the user to edit an employee’s information
![Page 12: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/12.jpg)
Class Diagram
Employee EmployeeDialog
EmployeeModel EmployeeManagerView
*
1
0..1
1
0..1
1 = contains just one0..1 = contains zero or one* = contains zero or more
![Page 13: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/13.jpg)
Design: The Attributes of the Employee Class
• Development is incremental, so work bottom-up, starting with Employee
• What information does an employee contain?– a name– the hours worked for each of five days
![Page 14: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/14.jpg)
Constraints on the Attributes
• There are exactly five days
• Any hours over 8 * the number of days count for overtime
• Overtime pay is 1.5 * the regular pay rate
• Hours are whole numbers
• Pay rate is a real number
![Page 15: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/15.jpg)
Design: The Behavior of the Employee Class
• get or set the name
• get or set the pay rate
• get or set the hours of each day
• get the total pay
• get the total hours worked
![Page 16: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/16.jpg)
Other Useful Behavior
• obtain a string representation of an employee
• compare two employees for equality
• compare two employees for less than or greater than
• clone (copy) an employee
• transfer an employee to and from a file
![Page 17: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/17.jpg)
Constructors
• A default constructor will initialize an employee’s data to reasonable values
• A second constructor allows the client to supply the data
![Page 18: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/18.jpg)
Design: More Details• Specify the interface (a set of public method
signatures)
• Choose the data structures to represent the attributes
• Choose the algorithms for the methods
• Write a tester program to illustrate their use
![Page 19: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/19.jpg)
The Employee Interfacepublic Employee()
public Employee(String name, double payRate, int[] hoursWorked)
public String getName()
public void setName(String newName)
public double getPayRate()
public void setPayRate(double newRate)
public int getHours(int whichDay)
public void setHours(int whichDay, int hours)
![Page 20: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/20.jpg)
The Employee Interfacepublic int getTotalHours()
public double computePay()
public String toString()
public boolean equals(Object other)
public int compareTo(Object other)
public Object clone()
![Page 21: Object-Oriented Programming Developing an Application](https://reader030.vdocuments.mx/reader030/viewer/2022032612/56649f0d5503460f94c20fbe/html5/thumbnails/21.jpg)
The Employee Interfacestatic public final int MAX_DAYS = 5;
static public final int MAX_REGULAR_HOURS = MAX_DAYS * 8;
static public final double OVERTIME_RATE = 1.5;