《JAVA OOP开发》英文版 Chapter 12 Reusable classes and packages

Chapter 12 Reusable Classes and Packages 2000 McGraw-Hl‖ Introduction to Object-Oriented Programming with Java-Wu Chapter 12-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 1 Chapter 12 Reusable Classes and Packages

Chapter 12 objectives After you have read and studied this chapter, you should be able to e Describe four different object categories and use them effectively in designing classes e Define a package and place reusable classes in it e Write a method that calls the superclass's method explicitly by using the reserved word super e Define overloaded methods C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 12-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 2 Chapter 12 Objectives After you have read and studied this chapter, you should be able to Describe four different object categories and use them effectively in designing classes. Define a package and place reusable classes in it. Write a method that calls the superclass’s method explicitly by using the reserved word super. Define overloaded methods

Reusability r We say a class is reusable if it can be used in different programs Classes in the javabook package is highly reusable r Not all classes have to be reusable. We may design a class specifically for a given program. Such class is not reusable r We must design the classes accordingly. If we intend the class to be reusable, then we need to design it so that the class is indeed reusable r One way to increase the reusability is to design a class that implements a single well-defined task C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 12-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 3 Reusability We say a class is reusable if it can be used in different programs. Classes in the javabook package is highly reusable. Not all classes have to be reusable. We may design a class specifically for a given program. Such class is not reusable. We must design the classes accordingly. If we intend the class to be reusable, then we need to design it so that the class is indeed reusable. One way to increase the reusability is to design a class that implements a single well-defined task

Object Categories r To aid in designing a single-task class, we divide object tasks into four categories o A user interface object handles the interaction between the end user and the program o A controller object supervises other objects in the program An appllication logic object captures the logic of the real world for which the program is written o a storage object takes care of file input and output. C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 4 Object Categories To aid in designing a single-task class, we divide object tasks into four categories: A user interface object handles the interaction between the end user and the program. A controller object supervises other objects in the program. An application logic object captures the logic of the real world for which the program is written. A storage object takes care of file input and output

Method Overriding r Two techniques to make a class more reusable are method overriding and method overloading r We say a method of a subclass overrides the inherited method when we redefine the method in the subclass Example: setvisible of drawing board overrides setvisible of MainWindow public class DrawingBoard extends MainWindow public void setvisible( boolean state The reserved word super setVisible( state )i super refers to the graphic= getGr aphics()i superclass } C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 5 Method Overriding Two techniques to make a class more reusable are method overriding and method overloading. We say a method of a subclass overrides the inherited method when we redefine the method in the subclass. Example: setVisible of DrawingBoard overrides setVisible of MainWindow public class DrawingBoard extends MainWindow { . . . public void setVisible( boolean state ) { super.setVisible( state ); graphic = getGraphics( ); } . . . } The reserved word super refers to the superclass

Method Overloading r The signature of a method is determined by the method name and the number and data types of parameters. r If multiple methods have the same method name but different signatures the method name is overloaded and we call these methods overloaded public void drawRectangle( int x, int y, int width, int length public void drawRectangle( Rectangle rect drawRectangle is overloaded C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 12-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 6 Method Overloading The signature of a method is determined by the method name and the number and data types of parameters. If multiple methods have the same method name but different signatures, the method name is overloaded and we call these methods overloaded. public void drawRectangle( int x, int y, int width, int length ) { . . . } public void drawRectangle( Rectangle rect ) { . . . } drawRectangle is overloaded

Overloading constructors r As we can overload regular methods we can overload constructors a class with multiple constructors allows the programmer a flexibility in creating instances. This improves the usability of the class public Drawing Board( this(DRAWING board")i This calls the other constructor public DrawingBoard( string title setTitle( title setResizable( false setBackground( Color. white )i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 7 Overloading Constructors As we can overload regular methods, we can overload constructors. A class with multiple constructors allows the programmer a flexibility in creating instances. This improves the usability of the class. public DrawingBoard( ) { this( “DRAWING BOARD”); } public DrawingBoard( String title ) { setTitle( title ); setResizable( false ); setBackground( Color.white ); } This calls the other constructor

Reusable eggypeggy r Problem statement Write a Class that converts a given string to an Eggy-peggy string by placing the programmer-specified word in front of all vowels in the given string. If the programmer does not specify the word, then the default prefix egg"will be used. r Capabilities e The class is not tied to any particular program or user interface e The class provides an application logic of playing the Eggy-Peggy game. C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 8 Reusable EggyPeggy Problem Statement Write a class that converts a given string to an Eggy-Peggy string by placing the programmer-specified word in front of all vowels in the given string. If the programmer does not specify the word, then the default prefix “egg” will be used. Capabilities The class is not tied to any particular program or user interface. The class provides an application logic of playing the Eggy-Peggy game

EggyPeggy Development Steps 1. Start with a class skeleton. Define the necessary data members and constructors 2. Implement the setPrefix Word and convert methods Add any private methods as necessary C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 12-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 9 EggyPeggy Development Steps 1. Start with a class skeleton. Define the necessary data members and constructors. 2. Implement the setPrefixWord and convert methods. Add any private methods as necessary

Reusable hilo r Problem statement Write an application ogic class that will play Hi-Lo games. The objective of the game is for the user to guess the computer-generated secret number in the least number of tries. The programmer can set the low and high bounds of a secret number and the number of guesses the user is allowed. If the number of guesses allowed is not set by the programmer then it is set by the HiLo object based on the designated low and high bounds. The default ow and high bounds are 1 and 100, The default number of guesses for the default low and high bounds is. C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 12 - 10 Reusable HiLo Problem Statement Write an application logic class that will play Hi-Lo games. The objective of the game is for the user to guess the computer-generated secret number in the least number of tries. The programmer can set the low and high bounds of a secret number and the number of guesses the user is allowed. If the number of guesses allowed is not set by the programmer, then it is set by the HiLo object based on the designated low and high bounds. The default low and high bounds are 1 and 100. The default number of guesses for the default low and high bounds is 7
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《JAVA OOP开发》英文版 Chapter 11 File Input and Output.ppt
- 《JAVA OOP开发》英文版 Chapter 10 Sorting and Searching.ppt
- 《JAVA OOP开发》英文版 Chapter 9 objectives.ppt
- 《JAVA OOP开发》英文版 Chapter 8 Characters and strings.ppt
- 《JAVA OOP开发》英文版 Chapter 7 Repetition Statements.ppt
- 《JAVA OOP开发》英文版 Chapter 6 Selection statements.ppt
- 《JAVA OOP开发》英文版 Chapter 5 Processing Input with Applets.ppt
- 《JAVA OOP开发》英文版 Chapter 4 Defining Instantiable Classes.ppt
- 《JAVA OOP开发》英文版 Chapter 3 Numerical Data.ppt
- 《JAVA OOP开发》英文版 Chapter 2 Java Programming Basics.ppt
- 《JAVA OOP开发》英文版 Chapter 1 Introduction to Object-oriented Programming and Software Development.ppt
- 《JAVA OOP开发》英文版 Introduction to Computers and Programming Languages.ppt
- 《Windows DNA应用程式》 面向对象分析与设计讲义.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第四章 第四讲 分支结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十二章 文件.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十一章 复杂数据类型及排序.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第六讲 数组.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第六讲 数组.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章(7-2)指针与指针变量.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第五章 循环结构.ppt
- 《JAVA OOP开发》英文版 Chapter 13 GUI Objects and Event-Driven Programming.ppt
- 《JAVA OOP开发》英文版 Chapter 14 Inheritance and Polymorphism.ppt
- 《JAVA OOP开发》英文版 Chapter 15 Case Study Class Roster Maintenance program.ppt
- 《JAVA OOP开发》英文版 Chapter 16 Chapter 16 Recursive algorithms.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第一章 绪论.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第七章 牛行接与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第三章 MCS-51单片机指令系统.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第九章 A/D、D/A转换接口.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第二章 MCS-51学机组成理.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第五章 输入/输出与中断.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第八章 并行接口与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第六章 定时器/计数器及应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第十章 单片机应用系统设计与开发.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第四章 MCS-51单片机存储器的扩展.ppt
- 《网络安全设计》 第一章 安全设计简介.ppt
- 《网络安全设计》 第二章 创建网络安全计划.ppt
- 《网络安全设计》 第三章 确定网络安全威胁.ppt
- 《网络安全设计》 第四章 分析安全风险.ppt
- 《网络安全设计》 第五章 创建物理资源安全设计.ppt
- 《网络安全设计》 第六章 创建计算机安全设计.ppt