Buliding Object-Oriented Applications in PowerBuilder  Module 12 : Polymorphism
Objectives <ul><li>Describe operational and inclusional polymorphism </li></ul><ul><li>Explain the different techniques to...
Topics <ul><li>O verview of Polymorphism </li></ul><ul><li>Operational Polymorphism </li></ul><ul><li>Inclusional Polymorp...
Overview of Polymorphism <ul><li>The same method signature (name, arguments, and argument types) defined in different clas...
Polymorphism  <ul><li>The following messages all save changes, but use different method names: </li></ul><ul><ul><ul><li>w...
Categories of Polymorphism <ul><li>Operational  – Polymorphic methods for  unrelated  classes </li></ul><ul><ul><li>Must d...
Operational Polymorphism Example *Note: there is no ancestor with of_Save()  or ue_retrieve of_Save( ) ue_Retrieve w_ar_ma...
Operational Polymorphism Static Messaging <ul><li>For Example, the menuitem m_save script: </li></ul><ul><ul><ul><li>strin...
Operational Polymorphism  Dynamic  Messaging Example <ul><li>Messages are generic but with more overhead </li></ul><ul><li...
Inclusional Polymorphism Example <ul><li>Common user-defined ancestor </li></ul><ul><li>Code in answer  can  be empty (vir...
Inclusional Polymorphism Example <ul><li>The code in the menu would reassign ParentWindow reference to ancestor class: </l...
Summary <ul><li>Polymorphism implies using the same method signatures for different object classes. </li></ul><ul><li>Oper...
Summary Questions
Lab Setup <ul><li>What you will need to do in the lab: </li></ul><ul><ul><li>Define polymorphic functions   </li></ul></ul>
Lab Debriefing <ul><li>Define of_save( ) in the ancestor w_sheet </li></ul>
Lab Debriefing <ul><li>Redefine of_save at a descendent level  </li></ul>
Lab Debriefing
 
Upcoming SlideShare
Loading in …5
×

Booa8 Slide 12

891 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
891
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Booa8 Slide 12

    1. 1. Buliding Object-Oriented Applications in PowerBuilder Module 12 : Polymorphism
    2. 2. Objectives <ul><li>Describe operational and inclusional polymorphism </li></ul><ul><li>Explain the different techniques to generically pass dynamic methods in messages </li></ul><ul><li>Describe how to pass static methods in messages </li></ul>
    3. 3. Topics <ul><li>O verview of Polymorphism </li></ul><ul><li>Operational Polymorphism </li></ul><ul><li>Inclusional Polymorphism </li></ul>
    4. 4. Overview of Polymorphism <ul><li>The same method signature (name, arguments, and argument types) defined in different classes </li></ul><ul><li>The behavior can be different </li></ul><ul><li>Examples: </li></ul><ul><ul><li>cb_1.SetFocus( ) </li></ul></ul><ul><ul><li>dw_1.SetFocus( ) </li></ul></ul>
    5. 5. Polymorphism <ul><li>The following messages all save changes, but use different method names: </li></ul><ul><ul><ul><li>w_cust.of_SaveCust( ) </li></ul></ul></ul><ul><ul><ul><li>w_invoice.of_SaveInvoice( ) </li></ul></ul></ul><ul><ul><ul><li>w_order.of_SaveOrder( ) </li></ul></ul></ul><ul><li>Using the same name would provide more consistency: </li></ul><ul><ul><ul><li>w_cust.of_Save( ) </li></ul></ul></ul><ul><ul><ul><li>w_invoice.of_Save( ) </li></ul></ul></ul><ul><ul><ul><li>w_order.of_Save( ) </li></ul></ul></ul>
    6. 6. Categories of Polymorphism <ul><li>Operational – Polymorphic methods for unrelated classes </li></ul><ul><ul><li>Must define methods for each appropriate class </li></ul></ul><ul><ul><li>May require complex CHOOSE CASE construct or dynamic messaging </li></ul></ul><ul><li>Inclusional – Polymorphic methods implemented within class hierarchies </li></ul>
    7. 7. Operational Polymorphism Example *Note: there is no ancestor with of_Save() or ue_retrieve of_Save( ) ue_Retrieve w_ar_main of_Save( ) ue_Retrieve w_inv_main of_Save( ) ue_Retrieve w_ap_main
    8. 8. Operational Polymorphism Static Messaging <ul><li>For Example, the menuitem m_save script: </li></ul><ul><ul><ul><li>string ls_classname </li></ul></ul></ul><ul><ul><ul><li>w_ar_main lw_ar_main </li></ul></ul></ul><ul><ul><ul><li>w_ap_main lw_ap_main </li></ul></ul></ul><ul><ul><ul><li>ls_classname = ParentWindow.ClassName( ) </li></ul></ul></ul><ul><ul><ul><li>CHOOSE CASE ls_classname </li></ul></ul></ul><ul><ul><ul><li>CASE 'w_ar_main' </li></ul></ul></ul><ul><ul><ul><li>lw_ar_main = ParentWindow // “cast” to correct class </li></ul></ul></ul><ul><ul><ul><li>lw_ar_main.of_Save( ) </li></ul></ul></ul><ul><ul><ul><li>CASE 'w_ap_main' </li></ul></ul></ul><ul><ul><ul><li>lw_ar_main = ParentWindow // “cast” to correct class lw_ap_main.of_Save( ) </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><ul><ul><li>CASE ELSE </li></ul></ul></ul><ul><ul><ul><li>END CHOOSE </li></ul></ul></ul>
    9. 9. Operational Polymorphism Dynamic Messaging Example <ul><li>Messages are generic but with more overhead </li></ul><ul><li>You don’t have to “cast” parentwindow to the appropriate type </li></ul><ul><li>Bypasses compiler checking </li></ul><ul><ul><li>ParentWindow.DYNAMIC of_Save( ) </li></ul></ul><ul><ul><li>ParentWindow.Event DYNAMIC ue_Retrieve( ) </li></ul></ul>
    10. 10. Inclusional Polymorphism Example <ul><li>Common user-defined ancestor </li></ul><ul><li>Code in answer can be empty (virtual functions) </li></ul>Methods defined in ancestor; descendants can optionally override or extend of_Save( ) ue_Retrieve w_ar_main ue_Retrieve w_inv_main of_Save( ) w_ap_main of_Save( ) ue_Retrieve {w_main}
    11. 11. Inclusional Polymorphism Example <ul><li>The code in the menu would reassign ParentWindow reference to ancestor class: </li></ul><ul><ul><ul><li>w_main lw_temp </li></ul></ul></ul><ul><ul><ul><li>lw_temp = ParentWindow // “cast” to ancestor </li></ul></ul></ul><ul><ul><ul><li>lw_temp.of_Save( ) </li></ul></ul></ul><ul><ul><ul><li>lw_temp.EVENT ue_Retrieve( ) </li></ul></ul></ul><ul><li>Enables generic static messaging </li></ul><ul><li>Not required to define methods at descendent level – simply write the appropriate code for that descendent </li></ul><ul><li>Requires the use of common ancestor class </li></ul>
    12. 12. Summary <ul><li>Polymorphism implies using the same method signatures for different object classes. </li></ul><ul><li>Operational polymorphism is the use of the same method name in unrelated classes. </li></ul><ul><li>Inclusional polymorphism makes use of inheritance hierarchies and common method names. </li></ul><ul><li>An ancestor method can contain no defined behavior. </li></ul><ul><li>A descendent class can extend or override ancestor behavior. </li></ul>
    13. 13. Summary Questions
    14. 14. Lab Setup <ul><li>What you will need to do in the lab: </li></ul><ul><ul><li>Define polymorphic functions </li></ul></ul>
    15. 15. Lab Debriefing <ul><li>Define of_save( ) in the ancestor w_sheet </li></ul>
    16. 16. Lab Debriefing <ul><li>Redefine of_save at a descendent level </li></ul>
    17. 17. Lab Debriefing

    ×