Booa8 Slide 02


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Booa8 Slide 02

    1. 1. Buliding Object-Oriented Applications in PowerBuilder Module 2: Objects And Classes
    2. 2. Objectives <ul><li>Define Object and Classes </li></ul><ul><li>Use Edit Source (system tree) / Export Syntax (Iibrary painter) to view the definition of classes </li></ul><ul><li>Add Properties and Methods to a class </li></ul>
    3. 3. Topics: Objects and Classes <ul><li>Definitions </li></ul><ul><li>Defining Classes </li></ul><ul><li>Viewing Class Definitions </li></ul><ul><li>What Can Be Added to a Class </li></ul><ul><li>Adding Properties to a Class </li></ul><ul><li>Adding Methods to a Class </li></ul>
    4. 4. Objects — Definition <ul><li>An object is represented by its: </li></ul><ul><ul><li>Properties: Visible, color, height </li></ul></ul><ul><ul><li>Property values (data): George, red, 5'8&quot; </li></ul></ul><ul><ul><li>Methods (behaviors): Pitches a baseball, eats anchovy pizza </li></ul></ul>
    5. 5. Classes — Definition <ul><li>A class defines a set of objects </li></ul><ul><li>Each object is an instance of its class </li></ul>Class Definition Object Instance
    6. 6. Defining Classes <ul><li>Done in Painters </li></ul><ul><ul><li>Window </li></ul></ul><ul><ul><li>Menu </li></ul></ul><ul><ul><li>User-Object </li></ul></ul><ul><ul><li>Application </li></ul></ul><ul><li>Based on Inheritance </li></ul>
    7. 7. New Objects Created Through Inheritance
    8. 8. Defining Classes <ul><li>Stored in PBLs, PBDs, DLLs, and EXEs </li></ul>
    9. 9. Syntax — Window Subclass of window class Class properties changed
    10. 10. Defining Classes <ul><li>User-defined classes of applications, menus, user objects, and windows can: </li></ul><ul><ul><li>Have new properties (instance variables) </li></ul></ul><ul><ul><li>Have new methods (events, object functions, and local external functions) </li></ul></ul>
    11. 11. Adding Properties — Instance Variables
    12. 12. Methods of a Class <ul><li>Methods are object behaviors </li></ul><ul><li>Represented by scripts associated with: </li></ul><ul><ul><li>Events </li></ul></ul><ul><ul><li>Functions </li></ul></ul>
    13. 13. System Methods <ul><li>Mapped to specific event ids. </li></ul><ul><li>You cannot add / change arguments </li></ul>Show/Hide Prototype Cannot Modify Arguments
    14. 14. Adding Methods — Events <ul><li>An event is a notification that an action has occurred </li></ul><ul><li>System events are operating system or PowerBuilder events </li></ul><ul><ul><li>Examples: Clicked, Open, Constructor, RButtonDown, RetrieveStart, DBError </li></ul></ul><ul><li>User-defined events can be: </li></ul><ul><ul><li>Added to windows, user objects, and window controls </li></ul></ul><ul><ul><li>Mapped to system events or unmapped </li></ul></ul>
    15. 15. User-Defined Events
    16. 16. Mapped Events <ul><li>Predefined events </li></ul><ul><ul><li>Dependent on operating system </li></ul></ul><ul><ul><li>ue_downkey ---> pbm_dwnkey </li></ul></ul><ul><li>Arguments and return data type are predefined </li></ul>
    17. 17. Unmapped Events <ul><li>An unmapped event: </li></ul><ul><ul><li>Is independent of system and PowerBuilder events </li></ul></ul><ul><ul><li>Is invoked via scripts only </li></ul></ul><ul><ul><li>Supports user-defined arguments and a user-specified return data type </li></ul></ul>
    18. 18. User-Defined Events Mapped or Unmapped Events Determined
    19. 19. Adding Methods — Functions <ul><li>Built-in functions: </li></ul><ul><ul><li>System (Global) functions </li></ul></ul><ul><ul><li>Class functions </li></ul></ul><ul><li>User-defined functions: </li></ul><ul><ul><li>Object functions </li></ul></ul><ul><ul><li>External functions </li></ul></ul>
    20. 20. Adding Methods — Object Functions <ul><li>Functions defined for a class are methods </li></ul><ul><li>A function definition consists of: </li></ul><ul><ul><li>Name </li></ul></ul><ul><ul><li>Return data type (optional) </li></ul></ul><ul><ul><li>Arguments and their data types (optional) </li></ul></ul><ul><ul><li>Script (optional) </li></ul></ul><ul><ul><li>Access privilege </li></ul></ul><ul><li>Can be defined for Application, Menu, Window, and UserObject classes </li></ul>
    21. 21. Adding Functions
    22. 22. Adding Functions
    23. 23. Adding Methods — External Functions <ul><li>Reside in DLLs or EXEs </li></ul><ul><li>Created outside of PowerBuilder (for example, using C++) </li></ul><ul><li>Must be declared to PowerBuilder </li></ul><ul><li>Can be called as any other function </li></ul><ul><li>Can be global or local </li></ul><ul><li>Can be defined at the object level for menus, user objects, and windows </li></ul>
    24. 24. Adding Methods — External Functions
    25. 25. Summary Events Yes (v8) Yes (v8) Yes Yes Yes Class Application Menu UserObject Window Window control Instance Variables Yes Yes Yes Yes No Object Function Yes Yes Yes Yes No External Function No Yes Yes Yes No
    26. 26. Summary <ul><li>A class has a name, properties, and methods. </li></ul><ul><li>A class is the definition of a set of objects. </li></ul><ul><li>An object is an instance of a class. </li></ul><ul><li>The four main PowerBuilder painters are: Application, Menu, User Object, and Window. </li></ul><ul><li>PowerBuilder class definitions are stored in libraries: </li></ul><ul><ul><li>PBLs for development </li></ul></ul><ul><ul><li>PBDs, DLLs and EXEs for an executable </li></ul></ul>
    27. 27. Summary Questions
    28. 28. Lab Setup <ul><li>What you will need to do the lab: </li></ul><ul><ul><li>Set the application search path </li></ul></ul><ul><ul><li>Connect to the Database </li></ul></ul><ul><ul><li>Add properties to a class as instance variables </li></ul></ul><ul><ul><li>Add function methods to a class Preview a window </li></ul></ul>
    29. 29. Lab Debriefing <ul><li>Created two instance variables: is_action and il_key </li></ul>
    30. 30. Lab Debriefing <ul><li>Created two methods to set properties </li></ul>
    31. 31. Lab Debriefing <ul><li>Created two methods to get properties </li></ul>
    32. 32. Lab Debriefing <ul><li>But we have not fully encapsulated these properties. (more in later chapters) </li></ul>Can you access these properties using direct access? Should you? But can you? What are some disadvantages of not fully encapsulating these?