tailieunhanh - Lecture Java: Chapter 10
Lecture Java: Chapter 10 (Polymorphism) focuses on defining polymorphism and its benefits, using inheritance to create polymorphic references, using interfaces to create polymorphic references, using polymorphism to implement sorting and searching algorithms. | Copyright © 2012 Pearson Education, Inc. Chapter 10 Polymorphism Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Polymorphism Polymorphism is an object-oriented concept that allows us to create versatile software designs Chapter 10 focuses on: defining polymorphism and its benefits using inheritance to create polymorphic references using interfaces to create polymorphic references using polymorphism to implement sorting and searching algorithms 9-2 Outline 9-3 Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching Binding Consider the following method invocation: (); At some point, this invocation is bound to the definition of the method that it invokes If this binding occurred at compile time, then that line of code would call the same method every time However, Java defers method binding until run time -- this is called dynamic binding or late binding Late binding provides flexibility | Copyright © 2012 Pearson Education, Inc. Chapter 10 Polymorphism Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Polymorphism Polymorphism is an object-oriented concept that allows us to create versatile software designs Chapter 10 focuses on: defining polymorphism and its benefits using inheritance to create polymorphic references using interfaces to create polymorphic references using polymorphism to implement sorting and searching algorithms 9-2 Outline 9-3 Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching Binding Consider the following method invocation: (); At some point, this invocation is bound to the definition of the method that it invokes If this binding occurred at compile time, then that line of code would call the same method every time However, Java defers method binding until run time -- this is called dynamic binding or late binding Late binding provides flexibility in program design 9-4 Polymorphism The term polymorphism literally means "having many forms" A polymorphic reference is a variable that can refer to different types of objects at different points in time The method invoked through a polymorphic reference can change from one invocation to the next All object references in Java are potentially polymorphic 9-5 Polymorphism Suppose we create the following reference variable: Occupation job; Java allows this reference to point to an Occupation object, or to any object of any compatible type This compatibility can be established using inheritance or using interfaces Careful use of polymorphic references can lead to elegant, robust software designs 9-6 Outline 9-7 Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching References and Inheritance An object reference can refer to an object of its class, or to an object of any class related to it by inheritance For example, if the Holiday class is used .
đang nạp các trang xem trước