Document 9654232

Download Report

Transcript Document 9654232

Matakuliah
Tahun
: T0104 – Metode Perancangan Program
: 2010
OBJECT ORIENTED DESIGN
FOR MORE THAN ONE CLASS
Pertemuan - 21
Pertemuan - 21
Object Oriented Design
For More Than One Class
Objectives
• To list the steps required to create an object-oriented
design for more than one class a problem
Steps in creating an object-oriented solution
using more than one class
•
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 More Than One Class
• EXAMPLE
– Examine Example 12.2 Calculate Employee’s Pay on pages
225 - 226.
Object Oriented Design
For More Than One Class
Problem Satatements: Calculate Employee’s Pay
•
•
Design a parent class named Employee that will calculate the weekly
pay for a company’s full time employees. The class is to receive the
employee’s number, name and hourly pay rate; validate the pay rate
(the pay rate must be numeric and less than or equal to $30.00 per
hour); and calculate the employee’s weekly pay, assuming that all fulltime employees work a 38 hour week.
You are then to design a child class called PartTimeEmployee that will
use the existing attributes and methods of its parent class, Employee.
The PartTimeEmployee class will receive an extra input value for the
number of hours worked, which it must validate (number of hours
worked must be valid and less than 38) and then use it to calculate
the employee’s weekly pay (pay rate times number of hours). For both
classes, the employee’s number, name and weekly pay are to be
displayed.
Object Oriented Design
For More Than One Class
OOD SOLUTIONS
Use four steps refered to Example 12.2 Calculate Employee’s Pay which
depicts all the processes involved in finding the solution as illustrated on
pages 226 through 232 of the textbook
– Step 1: Identify the classes and their attributes, responsibilities and
operations on pages 226 through 228
– Step 2: Determine the relationship between the objects and those
classes on pages 228
– Step 3: Design the algorithms for the operation, using structured design
on pages 228 through 231
– Step 4: Develop a test or driver algorithm to test the solution on pages
231 through 232
Summary
•
Most object-oriented programs need more than one
class
•
Classes can be related to each other through use,
by inheritance, or by composition
•
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