Đang chuẩn bị liên kết để tải về tài liệu:
Chapter 9 Polymorphism
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
.Polymorphism • Polymorphism is an object-oriented concept that allows us to create versatile software designs • Chapter 9 focuses on: defining polymorphism and its benefits using inheritance to create | Chapter 9 Polymorphism © 2004 Pearson Addison-Wesley. All rights reserved 9- Polymorphism Polymorphism is an object-oriented concept that allows us to create versatile software designs Chapter 9 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 © 2004 Pearson Addison-Wesley. All rights reserved 9- Outline Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching © 2004 Pearson Addison-Wesley. All rights reserved 9- Binding Consider the following method invocation: obj.doIt(); 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 . | Chapter 9 Polymorphism © 2004 Pearson Addison-Wesley. All rights reserved 9- Polymorphism Polymorphism is an object-oriented concept that allows us to create versatile software designs Chapter 9 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 © 2004 Pearson Addison-Wesley. All rights reserved 9- Outline Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching © 2004 Pearson Addison-Wesley. All rights reserved 9- Binding Consider the following method invocation: obj.doIt(); 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 © 2004 Pearson Addison-Wesley. All rights reserved 9- 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 © 2004 Pearson Addison-Wesley. All rights reserved 9- 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 © 2004 Pearson Addison-Wesley. All rights reserved 9- Outline Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching