Objectoriented Programming in OpenEdge ABL - PowerPoint PPT Presentation

1 / 61
About This Presentation
Title:

Objectoriented Programming in OpenEdge ABL

Description:

DEF VAR myExternalOrder AS CLASS ExternalOrder. myOrder = NEW Order ... DEFINE VAR dTotal AS DECIMAL. DEFINE VAR dDiscount AS DECIMAL INITIAL 0.85. ... – PowerPoint PPT presentation

Number of Views:754
Avg rating:3.0/5.0
Slides: 62
Provided by: evanbl
Category:

less

Transcript and Presenter's Notes

Title: Objectoriented Programming in OpenEdge ABL


1
Object-oriented Programming in OpenEdge ABL
Eric Debeij
Senior Solution Consultant Progress The
Netherlands
2
Terminology / Concept Review
  • Type - Strong-typing at compile time
  • Data member state
  • Methods behavior
  • Package type name fully qualified
  • Class Defines type data and methods
  • Object Runtime instance of a class
  • Interface Set of method definitions contract
  • Inheritance Inherit / specialize from super
    class

3
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

4
CLASSStatement
  • CLASS ltclass-typegt
  • package.classname
  • Single inheritence
  • Multiple interface

ProPath \Acme \Inv
\Order.cls \Order.r
File name Acme\Inv\Order.cls CLASS
Acme.Inv.Order END CLASS.
5
Class Statement - Optional Modifiers
  • FINAL
  • Class can not be inherited
  • USE-WIDGET-POOL
  • Creates an unnamed widget pool scoped to the
    class
  • Dynamically created handle based within the class
    placed in pool
  • Automatically deleted when class is destroyed
  • Can be specified anywhere in the hierarchy

6
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

7
Type Name
A Type is a definition
  • Type defines
  • State
  • Behavior
  • Inheritance relationship with other types
  • Enable strong-typing
  • Early binding - types determined at compile time
  • Type-consistency enforced at compile time and
    runtime
  • Full type names used to reference all classes

8
ExampleType Names
DEF VAR myOrder AS CLASS Acme.Inv.Order. DEF VAR
myInternalOrder AS CLASS Acme.Inv.InternalOrder. D
EF VAR myExternalOrder AS CLASS
Acme.Inv.ExternalOrder. myOrder NEW
Acme.Inv.Order ( ). myInternalOrder NEW
Acme.Inv.InternalOrder ( ). myExternalOrder NEW
Acme.Inv.ExternalOrder ( ).
9
USING Statement (10.1B)
Supports use of unqualified class name references
  • Identifies a package of classes or a single
    qualified class
  • Supported in both Procedures and Class files
  • Applied at compile time to unqualified class
    names
  • First executable statement in file

10
ExampleType Names with USING
USING Acme.Inv.. DEF VAR myOrder AS CLASS
Order. DEF VAR myInternalOrder AS CLASS
InternalOrder. DEF VAR myExternalOrder AS CLASS
ExternalOrder. myOrder NEW Order (
). myInternalOrder NEW InternalOrder (
). myExternalOrder NEW ExternalOrder ( ).
11
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

12
Methods
Methods define the behavior of an object
  • Keywords defining methods
  • METHOD
  • CONSTRUCTOR
  • DESTRUCTOR
  • Supports access modifiers
  • PRIVATE, PROTECTED, PUBLIC
  • Default is PUBLIC
  • Define data type it returns or VOID

13
Overriding
Specialization of methods
  • Method in subclass can specialize method in super
    class
  • Can replace or augment behavior in super class
  • Overridden method must have
  • Same signature
  • OVERRIDE keyword
  • To access super class methods use
  • SUPERmethod-name ( )

14
ExampleOverriding
  • Acme\Inv\Order.cls

METHOD PUBLIC DECIMAL getOrderTotal ( ) /
Calculate total / RETURN totalOrder. END
METHOD.
OVERRIDE keyword
Acme\Inv\InternalOrder.cls
METHOD PUBLIC OVERRIDE DECIMAL getOrderTotal (
) DEFINE VAR dTotal AS DECIMAL. DEFINE VAR
dDiscount AS DECIMAL INITIAL 0.85. dTotal
SUPERgetOrderTotal ( ). RETURN dTotal
dDiscount. END METHOD.
Pre / Post processing
15
Polymorphism
Same method can perform different behavior in
subclass
  • Execution of an overridden method in a subclass
    from a reference to a super class
  • Code written using super class
  • Tightly coupled to inheritance and overriding
  • Super class used at compile time, subclass
    assigned at runtime
  • Method call on super class dispatched to
    subclass method

16
Polymorphism Example
Acme.Inv.Order
METHOD PUBLIC DECIMAL getOrderTotal ( )
Acme.Inv.InternalOrder
METHOD PUBLIC OVERRIDE DECIMAL getOrderTotal ( )
Acme.Inv.ExternalOrder
METHOD PUBLIC OVERRIDE DECIMAL getOrderTotal ( )
17
Polymorphism - Example Continued
USING Acme.Inv.. DEFINE VARIABLE myOrder AS
CLASS Order. DEFINE VARIABLE bInternalCust AS
Logical. DEFINE VARIABLE dTotal AS Decimal. IF
(bInternalCust TRUE)THEN myOrder NEW
InternalOrder( ). ELSE myOrder NEW
ExternalOrder( ). dTotal myOrdergetOrderTotal(
).
Super Class Reference
Calls either Acme.Inv.InternalOrder or
Acme.Inv.ExternalOrder getOrderTotal ( )
18
Benefits of Polymorphism
  • Supports generic programming using super class or
    interface
  • Type used at compile time is super class or
    interface
  • Specialized behavior is called at runtime
    automatically
  • Built on inheritance and overriding

19
Overloading (10.1B)
Multiple methods with the same name
  • Different behavior / same name based on
    different signature
  • Routines with the same name
  • Constructors and Methods
  • Must have different signatures
  • Number, type and mode of parameters
  • Can not differ by only return type or access mode
  • No keyword to identify overloaded method

20
ExampleOverloading
No arguments
METHOD PUBLIC INTEGER getOrder ( ) END
METHOD. METHOD PUBLIC INTEGER getOrder
( INPUT iCustNum AS INTEGER) END
METHOD. METHOD PUBLIC INTEGER getOrder
( INPUT cSalesRep AS CHARACTER) END METHOD.
One argument - integer
One argument - character
21
Widening (10.1B)
Widening allows passing smaller data type for
larger
  • Object-oriented features are strongly-typed
  • Data type of parameter must match
  • DATE ? DATETIME ? DATETIME-TZ
  • INTEGER ? INT64 ? DECIMAL
  • Mode is significant Input, Output, Input-Output

22
ExampleWidening
METHOD PUBLIC INTEGER updateSalesDate ( INPUT
dtTransRecord AS DATETIME-TZ) END
METHOD. DEFINE VARIABLE myDate as
DATE. updateSalesRecord (INPUT myDate). DEFINE
VARIABLE myDateTime as DATETIME. updateSalesRecord
(INPUT myDateTime). DEFINE VARIABLE myDateTimeTZ
as DATETIME-TZ. updateSalesRecord (INPUT
myDateTimeTZ).
23
Hey, how does widening affect overloading?
  • Follows Overloading rules
  • Number of parameters must match exactly
  • Mode of parameter must match exactly
  • Relaxes data type matching rules
  • With widening the callers data type does not
    have to match exactly the callees data type
  • Overloading looks for the best match
  • Application design concern
  • May result in ambiguity error

24
ExampleWidening with Overloading
METHOD PUBLIC INTEGER updateSalesRecord ( INPUT
dtTransDate AS DATETIME-TZ, INPUT szSalesRep AS
CHARACTER) METHOD PUBLIC INTEGER
updateSalesRecord ( INPUT dtTransDate AS
DATE, INPUT szSalesRep AS CHARACTER) updateSal
esRecord (INPUT myDate, INPUT ABC). updateSalesR
ecord (INPUT myDateTime, INPUT ABC). updateSales
Record (INPUT myDateTimeTZ, INPUT ABC).
25
ExampleWidening with Overloading
METHOD PUBLIC INTEGER UpdateSalesRecord ( INPUT
dtTransDate AS DATETIME-TZ, INPUT iSalesAmount
AS INTEGER) METHOD PUBLIC INTEGER
UpdateSalesRecord ( INPUT dShipDate AS
DATE, INPUT deUnitsSold AS DECIMAL) UpdateSale
sRecord (INPUT myDate, INPUT myInt64). UpdateSales
Record (INPUT myDateTime, INPUT
myDecimal). UpdateSalesRecord (INPUT myDate,
INPUT myInteger).
Does not compile no match
Does not compile Ambiguity error
26
OverloadingOther considerations
  • Interoperability remains for static / dynamic
  • Table / Table-Handle
  • Dataset / Dataset-Handle
  • Overloading supported for class and interface
    types
  • May result in runtime ambiguity error
  • Buffer-field
  • Dynamic-function

27
Raising Error (10.1B)
  • Methods can raise error
  • RETURN ERROR lterror stringgt
  • Caller handles error condition
  • NO-ERROR
  • ON ERROR phrase
  • Retrieve lterror stringgt via RETURN-VALUE function

28
Error Raised in an Expression
  • All methods invoked left-to-right
  • Order of operands apply to results of methods
  • On error the result of expression is unchanged

myInt objAmethA( ) objBmethB( )
objCmethC( ).
29
ExampleError in an Expression
myInt objAmethA( ) objBmethB( )
objCmethC( ).
  • If methA raises error, methB and methC are not
    invoked
  • myInts value remains unchanged
  • If methB raises error, methC is not invoked
  • myInts value remains unchanged

30
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

31
Object Instantiation
  • Constructor of specified class is invoked on NEW
  • Constructor used to initialize data members
  • Constructor must call super classs constructor
  • Via SUPER ( )
  • OpenEdge provides a call to the default
    constructor
  • One with no parameters
  • Only if super class has no other constructor

32
ExampleObject Instantiation
Class A
  • refD NEW D (Ds params).
  • Invokes Ds constructor

Class B
CONSTRUCTOR PUBLIC C (Cs params ) SUPER (Bs
params). / Cs constructor body / END.
Class C
CONSTRUCTOR PUBLIC D (Ds params ) SUPER (Cs
params). / Ds constructor body / END.
Class D
33
Overloading of Constructor
  • Classes can have multiple constructors
  • Same rules as overloading for methods
  • Parameters specified in NEW determine which
    constructor is invoked

34
ExampleOverloading
No arguments
One argument - Integer
One argument - Character
CONSTRUCTOR PUBLIC Order ( ) / Constructor
code goes here / END CONSTRUCTOR. CONSTRUCTOR
PUBLIC Order ( INPUT iCustNum AS INTEGER) /
Constructor code goes here / END
CONSTRUCTOR. CONSTRUCTOR PUBLIC Order
( INPUT cSalesRep AS CHARACTER) /
Constructor code goes here / END CONSTRUCTOR.
35
Raising Error (10.1B)
  • Constructors can raise error
  • RETURN ERROR lterror stringgt
  • Caller handles error condition
  • NO-ERROR
  • ON ERROR phrase
  • Object reference unchanged
  • Destructor invoked for all classes in hierarchy
    whose constructor completed successfully

36
ExampleRaising Error in a Constructor
DEFINE VARIABLE refD AS CLASS D. refD NEW D ( )
NO-ERROR. IF ERROR-STATUSERROR THEN MESSAGE
INSTANTIATION FAILED RETURN-VALUE.
Class A
Class B
Class C
CONSTRUCTOR PUBLIC D (Ds params ) SUPER (Cs
params). / Ds constructor body / RETURN
ERROR ret code 101. END.
Class D
37
Object Deletion
  • Destructor of specified class is invoked on
    DELETE OBJECT
  • Destructor can not be called directly
  • OpenEdge calls all destructors in the class
    hierarchy
  • Destructors invoked from subclass to super class

38
ExampleObject Deletion
Class A
  • DELETE OBJECT refD.
  • Invokes Ds Destructor

Class B
DESTRUCTOR PUBLIC C ( ) / Cs destructor
/ END.
Class C
DESTRUCTOR PUBLIC D ( ) / Ds destructor
/ END.
Class D
39
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

40
Properties (10.1B)
  • Combine data member and method
  • Provide getter and setter accessors
  • Promotes data encapsulation
  • Optional access mode on accessors
  • Caller uses Property as data member
  • Support data encapsulation

41
ExampleDefining Property
DEFINE PUBLIC PROPERTY Salary AS DECIMAL GET (
) / Verify current users status /
RETURN Salary. END GET. PROTECTED SET
(INPUT iVal AS DECIMAL) / Is it within
range? / IF ival LT 100000 THEN
Salary ival. ELSE RETURN ERROR.
END SET.
42
ExampleAccessing a Property
  • Same syntax as setting / retrieving a data member
  • Can be used in expression

EmployeeObjSalary newValue. DISPLAY
EmployeeObjSalary. DeptObjRecord (INPUT
EmployeeObjName, INPUT
EmployeeObjSalary).
43
Example 2Defining Read-Only Property (Constant)
DEFINE PUBLIC PROPERTY pi AS DECIMAL INITIAL
3.14 GET ( ) RETURN pi. END GET.
DEFINE PUBLIC PROPERTY pi AS DECIMAL INITIAL
3.14 GET.
44
Example 3Defining Property not using default
memory
DEFINE PUBLIC PROPERTY numUnits AS INTEGER GET
( ) / Retrieve from temp-table current value
/ RETURN someTTcurrentInventory. END GET.
IF numRequested LT orderObjnumUnits
THEN orderObjprocessOrder(INPUT
numRequested). ELSE ...
45
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

46
Compiling Tips and Techniques
  • Strong-typing only works if you compile running
    compile-on-the-fly delays errors until runtime
  • Be safe always rebuild/compile your code
  • Recompiling only super classes can result in
    runtime errors always recompile subclasses that
    depend on super classes to be safe
  • Exceptions to this rule

47
Compiling Tips and Techniques
  • No recompile of subclasses required when
  • Methods / data is added to super class
  • Only implementation changes, not signature
  • When subclass accesses new methods and data, must
    recompile

A
B
E
I
F
J
C
K
G
D
H
48
Compiling Tips and Techniques
Build procedures (make.p)
A
  • COMPILER MULTI-COMPILE TRUE
  • Uses cache to store classes already compiled in
    session
  • Cache cleared when set to FALSE
  • OE Architect uses this option
  • Otherwise COMPILE builds full class hierarchy
    no timestamp check

B
D
C
E
F
H
G
49
Recommended Coding Standards
  • Always use packages in your type name
    Acme.DAOrder
  • First node is your company name
  • Class and Interface names use Pascal Case
  • Interface names start with leading I
    Acme.IList
  • Methods and data member use camelCase with
    lowercase first letter
  • Use object-oriented design patterns
    -encapsulation, abstraction, and delegation

50
Todays Agenda
  • Class Statement
  • Type Names
  • Methods
  • Object Hierarchy
  • Properties
  • Interface
  • Class Compiler Enhancements
  • Roadmap 10.1C and Beyond

51
10.1A
  • Class
  • Interface
  • Inheritance
  • Overriding
  • Access mode for data members
  • Strong type checking
  • Compiler improvements

52
10.1B
  • USING
  • Overloading
  • Properties
  • Default access mode methods - PUBLIC
  • Raising error from Constructor / Methods
  • Compiler system handle changes

53
Under Development
  • This talk includes information about potential
    future products and/or product enhancements.
  • What we are going to say reflects our current
    thinking, but the information contained herein is
    preliminary and subject to change. Any future
    products we ultimately deliver may be materially
    different from what is described here.

54
Targeted for 10.1C
  • Structured Error Handling
  • Similar to Try, Catch, Throw
  • Statics
  • Constructors, Data Members, Methods
  • Character to Longchar widening
  • NEW function

55
Future Release
  • Remote objects
  • Instantiating a class on the AppServer
  • Strongly typed application events
  • Publish / Subscribe for methods
  • Arrays of object references
  • Properties in interfaces
  • Inheritance of interfaces
  • Reflection
  • Dynamic invocation

56
In Summary
  • Object-oriented ABL supports standard
    object-oriented design patterns abstraction,
    encapsulation, inheritance, polymorphism
  • ABL supports standard object-oriented constructs
    interfaces, overriding, overloading,
    properties, strong-typing
  • More object-oriented functionality coming

57
Additional Object-oriented Exchange Sessions
58
For More Information, go to
  • PSDN
  • Progress eLearning Community
  • What's New OE 10.1 Object Oriented Programming
  • Documentation
  • 10.1B Object-oriented Programming manual
  • 10.1B New and Revised Features manual

59
Questions?
60
Thank you for your time!
61
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com