Matakuliah Tahun : T0104 – Metode Perancangan Program : 2010 OBJECT ORIENTED DESIGN FOR MULTIPLE CLASSES Pertemuan - 23 Pertemuan - 23 Object Oriented Design For Multiple Classes Objectives • To list the steps required to create an object-oriented design for multiple classes a problem Steps in creating an object-oriented solution for multiple classes • Four steps to follow to create an object-oriented solution: 1. Identify the classes and their attributes, responsibilities and operations 2. Determine the relationship between the objects and those classes 3. Design the algorithm for the operation, using structured design 4. Develop a test or driver algorithm to test the solution Object Oriented Design For Multiple Classes • EXAMPLE – Examine Example 13.1 Produce Employee Payslips on pages 242 Object Oriented Design For Multiple Classes Problem Satatements: Produce Employee Payslips • • Design a Payroll class to manage the employee payroll for a large company. The Payroll class is to read a file of employee timesheet and for each employee, call on the services of a Payslips class to c alculate that employee’s weekly pay and print a payslips. The Payslips class is to receive the employee’s number, pay rate and the number of hours worked in week. The class is to validate the pay rate field and the hours worked field and, if valid, compute the employee’s weekly pay and then print it and the input data onto payslip • Validation: . . . • Weekly pay calculation: . . . (Examine Example 13.1 Produce Employee Payslips on pages 242) Object Oriented Design For More Than One Class OOD SOLUTIONS Use four steps refered to Example 13.1 Calculate Employee’s Pay which depicts all the processes involved in finding the solution as illustrated on pages 243 through 249 of the textbook – Step 1: Identify the classes and their attributes, responsibilities and operations on pages 243 through 244 – Step 2: Determine the relationship between the objects and those classes on pages 244 through 245 – Step 3: Design the algorithms for the operation, using structured design on pages 245 through 248 – Step 4: Develop a test or driver algorithm to test the solution on pages 249 Summary • Most object-oriented programs need multiple classes • Classes can be related to each other through association, by aggregation or composition or by inheritance. • When classes are related by inheritance, all subclasses or child classes inherit the attributes and methods of the parent class, and supplement them with attributes and methods needed by the subtype Summary • There are four steps for designing a solution to a simple multiple-class problem: 1. Identify the classes and their attributes, responsibilities and operations. 2. Determine the relationship between the objects of those classes. 3. Design the algorithms for the operations using structured design. 4. Develop a test or driver algorithm to test the solution. The Code