Title: DEV12: Whats New in ObjectOriented ABL
1DEV-12 Whats New in Object-Oriented ABL
- OpenEdge 10.1C and beyond
Shelley Chase
OpenEdge Architect
2Agenda
- Overview of Object-oriented ABL
- 10.1C Features
- Static behavior and data
- Dynamic programming
- Error handling
- Data widening, NEW function, reserved
keywords, THIS-OBJECT - Futures
3What is Object-oriented ABL
OpenEdge 10.1 Releases
- Functionality centered around objects
- Classes encapsulate data and behavior
- Properties and variables
- Methods, constructors and destructor
- Inheritance shares common behavior
- Interfaces publish a common API
- Objects are the runtime instance of a class
- Strong-typing does compile time validation
- Can be combined with procedures
4Benefits of Procedural and OO Programming
OpenEdge is committed to both programming models
- Procedures and Classes
- Modular programming
- Supports reuse of common behavior (super)
- Maps well to OpenEdge Reference Architecture
- Classes only
- Programming errors caught early by compiler
- Natural integration with modeling tools and other
Object-oriented platforms like .NET - Modern programming model (used at most
universities)
5Agenda
- Overview of Object-oriented ABL
- 10.1C Features
- Static behavior and data
- Dynamic programming
- Error handling
- Data widening, NEW function, reserved
keywords, THIS-OBJECT - Futures
6Wouldnt It Be Great If
- Classes supported global variables within a
session? - You could always get a reference to the same
object every time you wanted to without keeping
track of anything?
7A Step Back Instance Data
Separate copy of data for each instance
- Always need to NEW an object to access members
- Unique data segment for each instance
MyClass
Data
Data
Data
Data
OpenEdge Runtime
DEV-12 Whats New in the Object-Oriented ABL
8Instance Data
Count 1 Name Joe
CLASS MyClass DEFINE PUBLIC PROPERTY Count
AS INT GET. SET. DEFINE PUBLIC
PROPERTY Name AS CHARACTER GET. SET.
CONSTRUCTOR MyClass ( inName AS CHARACTER )
Name inName. Count Count 1. END
CONSTRUCTOR. END CLASS.
DEF VAR myClassRef AS CLASS MyClass. myClassRef
NEW CLASS MyClass( Joe ). DELETE OBJECT
myClassRef. myClassRef NEW CLASS MyClass(
Tim ). DELETE OBJECT myClassRef. myClassRef
NEW CLASS MyClass( Ann ). DELETE OBJECT
myClassRef.
Count 1 Name Tim
Count 1 Name Ann
9Classes and Static Data
One copy of data for the session
- Access to static members do not require a NEW
object - One global data segment
MyClass
Static Data
Static Data
Static Data
Static Data
OpenEdge Runtime
10Static Data
Count 2 Name Tim
Count 1 Name Joe
Count 3 Name Ann
CLASS MyClass DEFINE PUBLIC STATIC PROPERTY
Count AS INT GET. SET. DEFINE PUBLIC
STATIC PROPERTY Name AS CHARACTER GET.
SET. CONSTRUCTOR MyClass ( inName AS CHARACTER
) Name inName. Count Count 1.
END CONSTRUCTOR END CLASS.
MyClassCount MyClassCount 1. MyClassName
Joe. MyClassCount MyClassCount
1. MyClassName Tim. MyClassCount
MyClassCount 1. MyClassName Ann.
11Classes are not Static
- Mix of instance and static members allowed
- Static members accessed using class type name
- Instance members accessed using object reference
- Unqualified references allowed inside class
- Static members created before instances
- Static constructor runs before instances
12ABL Static Data Typed Global Data
- Definition of static properties and data members
- Useful for session-wide data
- Variables, buffers, temp-tables, queries,
datasets, data sources - Available anywhere in the session
- Single instance life-cycle controlled by the AVM
- Access using class type name
DEFINE PUBLIC STATIC PROPERTY Count AS INT
GET. SET.
MESSAGE MyClassCount.
13ABL Static Constructor
- Definition of static constructor
- Useful to initialize static data
- Only one static constructor per class
- No arguments or access mode
- Can access STATIC data of the class
- Can RUN procedures
- Can NEW classes (even this one!)
- Run automatically before any class member access
is allowed
CONSTRUCTOR STATIC MyClass ( ) Count 0. /
Initialize static counter / END.
14ABL Static Methods
- Definition of static methods
- Useful when instance data is not required
- Can access STATIC data of the class
- Can RUN procedures
- Can NEW classes (even this one!)
- Available anywhere in the session
- Access using class type name
METHOD STATIC PUBLIC INT DisplayMessage( c AS
CHAR ) MESSAGE c VIEW-AS ALERT-BOX. END.
MyClassDisplayMessage( Statics are cool ).
15Accessing a Static Class Member
/ MyClass class not instantiated / MESSAGE
MyClassCount VIEW-AS ALERT-BOX.
- Access static data member Count
- Runtime checks if static class members are
loaded its not so
MyClass
16Accessing a Static Class Member
/ MyClass class not instantiated / MESSAGE
MyClassCount VIEW-AS ALERT-BOX.
- Access static data member Count
- Runtime checks if static class members are
loaded its not so - Creates static global data segment
- ttUsers and Count
MyClass
STATIC ttUsers Count
17Accessing a Static Class Member
/ MyClass class not instantiated / MESSAGE
MyClassCount VIEW-AS ALERT-BOX.
- Access static data member Count
- Runtime checks if static class members are
loaded its not so - Creates static global data segment
- ttUsers and Count
- Runs static constructor
- Initialize Count and ttUsers
MyClass
STATIC ttUsers Count 0
Joe, 3 Tim, 2 Ann, 5
18Accessing a Static Class Member
/ MyClass class not instantiated / MESSAGE
MyClassCount VIEW-AS ALERT-BOX.
- Access static data member Count
- Runtime checks if static class members are
loaded its not so - Creates static global data segment
- ttUsers and Count
- Runs static constructor
- Initialize Count and ttUsers
- Gets value of Count
MyClass
STATIC ttUsers Count 0
19Newing a Class with Static Members
DEFINE VAR objRef AS MyClass. objRef NEW CLASS
MyClass( Joe ).
MyClass
- NEW an instance of MyClass
- Runtime checks if static class members are
loaded it is.
STATIC ttUsers Count 0
20Newing a Class with Static Members
DEFINE VAR objRef AS MyClass. objRef NEW CLASS
MyClass( Joe ).
MyClass
- NEW an instance of MyClass
- Runtime checks if static class members are
loaded it is. - Creates local data segment
- name
STATIC ttUsers Count 0
Instance name
21Newing a Class with Static Members
DEFINE VAR objRef AS MyClass. objRef NEW CLASS
MyClass( Joe ).
MyClass
- NEW an instance of MyClass
- Runtime checks if static class members are
loaded it is. - Creates local data segment
- name
- Runs instance constructor
- Sets instance data name
- Increments static data Count
STATIC ttUsers Count 1
Instance name Joe
22Newing a Class with Static Members
DEFINE VAR objRef AS MyClass. objRef NEW CLASS
MyClass( Joe ).
MyClass
- NEW an instance of MyClass
- Runtime checks if static class members are
loaded it is. - Creates local data segment
- name
- Runs instance constructor
- Sets instance data name
- Increments static data Count
- Assigns new instance to object
reference
STATIC ttUsers Count 1
Instance name Joe
23Newing a Class with Static Members
DEFINE VAR objRef2 AS MyClass. objRef2 NEW
CLASS MyClass( Tim ).
- NEW an instance of MyClass
- Runtime checks if static class members are
loaded it is. - Creates local data segment
- name
- Runs instance constructor
- Sets instance data name
- Increments static data Count
- Assigns new instance to object reference
MyClass
STATIC ttUsers Count 2
Instance name Joe
Instance name Tim
24Newing a Class with Static Members
DEFINE VAR objRef3 AS MyClass. objRef3 NEW
CLASS MyClass( Ann ).
- NEW an instance of MyClass
- Runtime checks if static class members are
loaded it is. - Creates local data segment
- name
- Runs instance constructor
- Sets instance data name
- Increments static data Count
- Assigns new instance to object reference
MyClass
STATIC ttUsers Count 3
Instance name Joe
Instance name Tim
Instance name Ann
25Singleton Design Pattern
- Single instance of the class
- Available from anywhere within the session
- Loaded on demand
26Demo Singleton Class
27Developing with STATIC Members
Static lifecycle controlled by OpenEdge Runtime
- Static class members loaded for the life of the
session - When a .cls file is changed and re-compiled, the
static portion is NOT refreshed - Caution during development
- One active session shared by application and
development environment - Recompile does not reload any static changes
- Runtime error for mismatches can occur
- Session must be restarted
28Developing with STATIC Members
Static lifecycle controlled by OpenEdge Runtime
- Static class members loaded for the life of the
session - When a .cls file is changed and re-compiled, the
static portion is NOT refreshed - Caution during development
- One active session shared by application and
development environment - Recompile does not reload any static changes
- Runtime error for mismatches can occur
- Session must be restarted
Use Architect Launch Configurations
DEV-12 Whats New in the Object-Oriented ABL
29Wouldnt It Be Great If
- You could create an instance of a class passing
in a character expression for the class type name
at runtime?
DYNAMIC-NEW and DYNAMIC-CAST
30Dynamic Programming in OO ABL
OO Strong-typing restricts dynamic programming
- DYNAMIC-NEW
- New a class using a character expression and its
constructor parameters - Object reference is normally a super class
- DYNAMIC-CAST
- Cast an object reference to a type using a
character expression - Full Progress.Lang.Class reflection API still on
roadmap
31Dynamic Object Creation
- DYNAMIC-NEW
- Used to create a new instance
- Fully qualified character type name
- USING is not used
- Common parameter list
- Returns a strongly-typed object
- Type checked at runtime
METHOD BusinessEntity CreateBE( beType AS CHAR)
DEFINE VARIABLE myObj AS BusinessEntity. myObj
DYNAMIC-NEW STRING(BE beType)(parm1, ).
RETURN myObj. END METHOD.
BE beType
32Dynamic Object Casting
- DYNAMIC-CAST
- Used to cast an object reference
- Fully qualified character type name
- USING is not used
- Returns a strongly-typed object
- Type checked at runtime
METHOD BusinessEntity CreateBE( beType AS CHAR)
DEFINE VARIABLE myObj AS BusinessEntity. myObj
DYNAMIC-NEW STRING(BE beType)(parm1, ).
DYNAMIC-CAST( myObj,STRING(BE beType).
RETURN myObj. END METHOD.
BE beType
BE beType
33ClassFactory Design Pattern
- Class returns different types of classes
- Available from anywhere within the session
- Alternative is a large CASE statement
34Demo Class Factory
35Wouldnt It Be Great If
- ABL had a common way to deal with all errors
(system and application)? - An error could be thrown out of the local block /
procedure and handled elsewhere?
- Structured Error Handling
36Structured Error Handling
- TRY CATCH model
- Based on new built-in error objects
- Uses existing ABL blocks DO, REPEAT,
- System and application errors treated equally
- Can be used in classes and procedures
- Fully integrated with existing error handling
- NO-ERROR
- ERROR-STATUS
- RETURN ERROR
37Error Object Hierarchy
Progress.Lang.Object
Progress.Lang. Error ltltinterfacegtgt
Progress.Lang.ProError
System Errors
Application Errors
Progress.Lang. AppError
Progress.Lang. SysError
Progress.Lang. SoapFaultError
User-Defined Error Objects
38Error Handling Example System Error
- CATCH put on existing FOR EACH block
FOR EACH Customer FIND Order 1000. / Fails
/ MESSAGE "Never reach here". CATCH err AS
Progress.Lang.SysError / Handle error here
/ MESSAGE errGetMessage(1). END CATCH.
END.
39Error Handling Example Application Error
- CATCH put on existing DO block for running a
procedure
DO ON ERROR, UNDO LEAVE RUN doIt.p. / RETURNS
AppError / MESSAGE "Never reach here".
CATCH err AS Progress.Lang.AppError /
Handle error here / MESSAGE
errReturnValue. END CATCH. END.
40Wouldnt It Be Great If
- CHARACTER data could be passed for a LONGCHAR
- NEW could be called as an expression
- Reserved keywords could be used for class member
names - THIS-OBJECT could be used to qualify a class
member
41Data Widening
Strong-typing rules for compatibility
- More flexible parameters passing
- 10.1B
- New for 10.1C
Narrower to Wider INTEGER gt INT64
gt DECIMAL DATE gt DATETIME gt DATETIME-TZ
Narrower(32K) to Wider (1GB) CHARACTER gt
LONGCHAR
42NEW function
- NEW statement ( 10.1A )
- Similar to an assignment
- Assigns an object reference to a variable
- NEW function ( 10.1C )
- Object created as part of an expression
- Returns a reference to new object
- No need to assign it to an intermediate variable
43Caution Using NEW function
- Object cleanup
- Object not assigned to anything memory leak!
- Object assigned to something
- Parameter receiving object responsible for cleanup
MESSAGE Using NEW function (NEW
myObject())myMethod( ).
RUN myProc.p ( INPUT NEW myObject() ).
44Caution Using NEW function
- Object cleanup
- Object not assigned to anything memory leak!
- Object assigned to something
- Parameter receiving object responsible for cleanup
Garbage Collection planned for 10.2A
MESSAGE Using NEW function (NEW
myObject())myMethod( ).
RUN myProc.p ( INPUT NEW myObject() ).
DEV-12 Whats New in the Object-Oriented ABL
45Reserved Keywords in Classes
- ABL Reserved Keywords can be used for
- Class names
- Best to prefix with packages
- Method names
CLASS Form CONSTRUCTOR PUBLIC Form( )
METHOD PUBLIC INT Create( )
DEFINE VAR myClass AS CLASS Form. myClass New
Form( ). myClassCreate( ).
46THIS-OBJECT as a Local Qualifier
- Qualifier used inside a class when accessing
local method, variable, and property names - Identifies member as class instance
- Enables content assist in Architect
- Required when a local method name is a reserved
keyword
CLASS Form CONSTRUCTOR PUBLIC Form( )
THIS-OBJECTCreate( ). END. METHOD PUBLIC INT
Create( )
47Agenda
- Overview of Object-oriented ABL
- 10.1C Features
- Static behavior and data
- Dynamic programming
- Error handling
- Data widening, NEW function, reserved
keywords, THIS-OBJECT - Futures
48Under Development
- This talk includes information about potential
future products and/or product enhancements. - What I am 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.
49Expected 10.2A Functionality
- Properties in Interfaces
- Defines data portion of contract
- Advanced GUI
- New UI Model Access to .NET UI Classes
- Garbage collection
- Automatic cleanup
- Array Enhancements
- Arrays of Objects
- Public arrays variables and properties
- Return value support for methods and functions
- Vector assignment
50A Glimpse Further into the Roadmap
- Strongly-typed events
- Define, Publish and Subscribe in Classes
- Remote objects
- Pass objects across an AppServer
- Abstract methods
- Force implementation in subclasses
- Inheritance for Interfaces
- Allow one Interface to inherit from another
51Relevant Exchange Sessions
- DEV-8 Structured Error Handling in the ABL
- DEV-22 Catch Me if You Can Practical
Structured Error Handling - DEV-38 OpenEdge ABL Info Exchange
- DEV-41 The Power of Polymorphism
52?
Questions
53Thank You
54(No Transcript)