1 / 9

More Object-Oriented Design

12. More Object-Oriented Design. Simple Program Design Third Edition A Step-by-Step Approach. 12. Objectives. To introduce the concept of multiple classes, polymorphism and method overriding in object-oriented design To describe relationships between classes

teal
Download Presentation

More Object-Oriented Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 12 More Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach

  2. 12 Objectives • To introduce the concept of multiple classes, polymorphism and method overriding in object-oriented design • To describe relationships between classes • To develop an object-oriented solution to a complex problem

  3. 12 Object-Oriented Design with Multiple Classes • The advantage of object-oriented programming languages is their usefulness in constructing large programs • In designing programs that use multiple classes, we need to consider not only the individual class design, but the relationships between the classes and therefore between the objects that are instantiated from those classes

  4. 12 Notations • Three popular methods for representing OO design were developed by James Rumbaugh, Grady Booch, and Ivar Jacobson • A fourth notation called UML, standing for Unified Modeling Langauge, has emerged from the work of Raumbaugh, Booch, and Jacobson • The notation in this chapter is based on a simplified UML standard • UML allows a designer to represent the relationship between classes, as well as between objects

  5. 12 Relationships Between Classes • When more than one class is used in a program, there can be one of three possible relationships between any two of the classes: 1. The simplest relationship is between two classes that are independent of each other in the program but perhaps able to use the services each provides 2. A class may be related to another class by inheritance 3. A class may need another class as part of itself in order to be able to function at all • Refer to the figure on page 194 of the textbook for an example of using UML notation

  6. 12 Polymorphism • Polymorphism, meaning many-shaped, describes the use of methods of the same name for a variety of purposes • See the diagram on page 194 of the textbook as an example of polymorphism • Method overriding occurs when a parent class provides a method, but the inheriting child class defines its own version of that method

  7. 12 Programming Example with Multiple Classes • Example 12.1 Calculate employee’s pay • Create a program that will read employee data from a file and, for each employee, compute the employee’s pay, which should then be printed together with the input data • Refer to the figures and steps and stages for the remainder of this example on pages 195 to 209 of the textbook

  8. 12 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

  9. 12 Summary • Through polymorphism, several methods may have the same name • Using method overriding, a child class may substitute the parent class version of a method with its own specific version • There are four steps in analyzing a multiple class problem: • identify the objects and the method to be performed • determine the relationship between the objects • design the algorithms for the methods using structured design • develop the mainline algorithm

More Related