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

Booa8 Slide 02

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