Title: DEV6: Advanced ObjectOriented Programming in the ABL
1DEV-6 Advanced Object-Oriented Programming in
the ABL
Evan Bleicher bleicher_at_progress.com
Shelley Chase schase_at_progress.com
Senior Development Manager
Architect
2Under 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.
3Agenda
- Order Entry System Object Model
- Abstract Programming with Classes
- Working with Datasets / Temp-tables in Classes
- Miscellaneous Topics
- Debugging with Classes
- Using SUPER in Classes
- Accessing Classes on the AppServer
- Error Handling policy for Classes
- Proper Encapsulation in Classes
- Compiler Tips and Tricks
- Coding Standards
4Order Entry System Object Model
Use OpenEdge Reference Architecture
Business Entity Interface between DA layer and
Presentation / Integration
Data Access Object Interface to Data Store
5Order Entry Object Model - Handout
Inherits
Inherits
Implements
Inherits
Implements
6Order Entry Object Model Data Access Layer
Super Order Class
PROTECTED TEMP-TABLE ttOline PROTECTED TEMP-TABLE
ttOrder PROTECTED DATASET dsOrder
CLASS Acme.DAOrderSuper
Inherits
Specific Order Class
CLASS Acme.DAOrder
Data Access Interface
Implements
INTERFACE Acme.IDataAccess
METHOD LONGCHAR selectRecords ()
METHOD LONGCHAR selectRecords ()
Implements
Specific Item Class
Navigation Interface
CLASS Acme.DAItem
INTERFACE Acme.IList
Implements
METHOD LONGCHAR selectRecords ()
7Order Entry Object Model Business Servicing
Layer
Business Entity Class
DEF VAR rDataObject AS CLASS Acme.IDataAccess ME
THOD VOID fetchWhere ( ) METHOD VOID saveChanges
( )
CLASS Acme.BusinessEntity
Inherits
Order Class
CLASS Acme.BEOrder
METHOD VOID processOrder( )
Specific Internal Order Class
Specific External Order Class
Inherits
Inherits
CLASS Acme.BEInternalOrder
CLASS Acme.BEExternalOrder
METHOD OVERRIDE VOID processOrder ( )
METHOD OVERRIDE VOID processOrder ( )
8Physical Architecture of A Class Hierarchy
COMPILE Acme/BEExternalOrder.cls SAVE.
ltpropathgt / Acme / BusinessEntity.cls
Inherits
ltpropathgt / Acme / BEOrder.cls
Inherits
ltpropathgt / Acme / BEExternalOrder.cls
9Physical Architecture of A Class Hierarchy
COMPILE Acme/BEExternalOrder.cls SAVE.
ltpropathgt / Acme / BusinessEntity.cls
Inherits
ltpropathgt / Acme / BEOrder.cls
Inherits
ltpropathgt / Acme / BEExternalOrder.cls
10Physical Architecture of A Class Hierarchy
COMPILE Acme/BEExternalOrder.cls SAVE.
ltpropathgt / Acme / BusinessEntity.cls
Inherits
ltpropathgt / Acme / BEOrder.cls
Inherits
ltpropathgt / Acme / BEExternalOrder.cls
11Agenda
- Order Entry System Object Model
- Abstract Programming with Classes
- Working with Datasets / Temp-tables in Classes
- Miscellaneous Topics
- Debugging with Classes
- Using SUPER in Classes
- Accessing Classes on the AppServer
- Error Handling policy for Classes
- Proper Encapsulation in Classes
- Compiler Tips and Tricks
- Coding Standards
12Abstract (Generic) Programming
- Define super class / interface for abstraction
- Define abstract methods
- Use abstract object
- Define object reference for super class /
interface - Set object ref to NEW subclass object
- Polymorphism causes method calls on object ref to
run method in subclass - Abstract code should be put in top most class
- Supports abstraction and reuse
13Choosing between Super Classes and Interfaces
- Both
- Define API (contract) for abstract programming
- Support polymorphism
- Super class
- Contain common code for sharing / augmenting
- Contain protected data members
- Interfaces
- Use when no common behavior exists
- Use to emulate multiple inheritance
14Abstract Programming Using Interfaces
- Define an interface
- Common methods put in interface
- Implementer must provide code for methods
INTERFACE Acme.IDataAccess
METHOD LONGCHAR selectRecords ()
Interface
Implements
CLASS Acme.DAOrder
CLASS Acme.DAItem
Implementer
Implementer
METHOD LONGCHAR selectRecords ()
METHOD LONGCHAR selectRecords ()
15Abstract Programming Using Super Classes
- Define a super class
- Common methods including code put in super class
- Optionally, subclass can override common code
CLASS Acme.BEOrder
METHOD VOID processOrder ( )
Super Class
CLASS Acme.BEInternalOrder
CLASS Acme.BEExternalOrder
Subclass
Subclass
METHOD OVERRIDE VOID processOrder ( )
METHOD OVERRIDE VOID processOrder ( )
16Abstract Programming Sample
- CLASS Acme.BusinessEntity
- / Define variable for interface type
/ - DEFINE PROTECTED VARIABLE rDataObject
- AS CLASS Acme.IDataAccess NO-UNDO.
- / Generic method works on any class that
- implements Acme.IDataAccess /
- METHOD PUBLIC LONGCHAR fetchWhere ()
- lcVar1 rDataObjectselectRecords ().
CLASS Acme.BEOrder CONSTRUCTOR BEOrder ( )
/ Create Order data object assign to super
class reference/ rDataObject NEW
Acme.DAOrder ( ). lcVar2 rDataObjectfetchWh
ere ().
17Demo of Abstract Programming
18Multiple Inheritance Using Interfaces
- Some older OO languages support multiple
inheritance - Newer OO languages support multiple APIs using
interfaces class inheritance is single
INTERFACE Acme.IDataAccess
METHOD LONGCHAR selectRecords ()
CLASS Acme.DAOrder
Implements
METHOD LONGCHAR selectRecords () METHOD
NextRecord ( ) METHOD PrevRecord ( )
INTERFACE Acme.IList
METHOD NextRecord ( ) METHOD PrevRecord ( )
19Agenda
- Order Entry System Object Model
- Abstract Programming with Classes
- Working with Datasets / Temp-tables in Classes
- Miscellaneous Topics
- Debugging with Classes
- Using SUPER in Classes
- Accessing Classes on the AppServer
- Error Handling policy for Classes
- Proper Encapsulation in Classes
- Compiler Tips and Tricks
- Coding Standards
20Datasets and Temp-Tables in Classes
- Defined in a class as either PROTECTED or PRIVATE
class data member - Passed as parameters to methods (like procs)
- Cannot be returned from a method (like UDFs)
- Temp-table columns can contain Progress.Lang.Objec
t - Automatically upcast when put into column
- CAST column value to subclass before use
21Using a Class from a Temp-Table Column
- Use TYPE-OF function with CAST
DEFINE VAR rOrder AS Acme.BEOrder. FOR EACH
myTT / See if column is an external order
/ IF TYPE-OF (myTT.rObj, Acme.BEExternalOrder)
THEN rOrder CAST (myTT.rObj,
Acme.BEExternalOrder). / See if column is
an internal order / ELSE IF TYPE-OF
(myTT.rObj, Acme.BEInternalOrder) THEN
rOrder CAST (myTT.rObj, Acme.BEInternalOrder).
END.
22Protected DataSets / Temp-Tables
- PROTECTED access in subclass automatic use
normal syntax - Better than passing BY-REFERENCE or BIND,
defining as SHARED - No need to include definition in subclass
PROTECTED TEMP-TABLE ttOline PROTECTED TEMP-TABLE
ttOrder PROTECTED DATASET dsOrder
CLASS Acme.DAOrderSuper
Inherits
CLASS Acme.DAOrder
FOR EACH ttOrder DISPLAY ttOrder.CustomerName
23ProDataSet Event Handlers
CLASS Acme. DAOrderSuper
- Callbacks can be methods as well as internal
procedures - Protected datasets can have handlers in subclass
Inherits
CLASS Acme.DAOrder
/ Set callback in subclass for dataset in super
class / hDSOrder dsOrderHANDLE. hDSOrderSET-C
ALLBACK (AFTER-FILL, postDSFill). METHOD
VOID postDSFill (DATASET dsOrder).
24Demo of Datasets and Temp-Tables
25Agenda
- Order Entry System Object Model
- Abstract Programming with Classes
- Working with Datasets / Temp-tables in Classes
- Miscellaneous Topics
- Debugging with Classes
- Using SUPER in Classes
- Accessing Classes on the AppServer
- Error Handling policy for Classes
- Proper Encapsulation in Classes
- Compiler Tips and Tricks
- Coding Standards
26Debugging Classes
- Debugger works with Classes
- Demos have been running classes in the debugger
- Steps into each constructor / destructor in
hierarchy - Shows polymorphism in action subclass method is
stepped into - Remember
- Open class file in debugger to see data members
27Using SUPER in Classes
- Use SUPER ( ) to call super class constructor
- Only valid in constructor
- Must be first line if present
- Use SUPERmethod-name ( ) to call a method higher
in the class hierarchy - Valid in constructor, destructor, methods
- Must specify method-name (unlike procedures)
28Running with Classes on an AppServer
Remote classes cannot be accessed from client
- Option 1 Classes on both client and server
- Provide serialize and deserialize methods
- Remote class access support coming
- Option 2 Dispatch procedure on AppServer
- Client interacts with dispatcher
- Data passed in temp-table or dataset
Client
AppServer
Data
Data
Data
Data
Data
Data
AppServer
Client
Dispatch.p
RUN dispatch.p SET h. RUN getData (myTT) in h.
Dataset / Temp-table
Data
Data
Data
Dataset / Temp-table
Dataset / Temp-table
Data
29Error Handling
- RETURN ERROR not allowed in classes
- Options
- Use output parameter or return type
- Use STOP mechanism
- Improved error handling coming!
30Options for Handling Errors in Constructor
- Constructor handles error
- Run DELETE THIS-OBJECT in constructor
- Automatically runs destructors for any successful
constructors in hierarchy - Caller checks object reference for unknown
- Compile/Deployment errors found during NEW
- Mismatched parameters, super class not found
- Automatically aborts new and cleans up
- Caller checks object reference for unknown or
ERROR-STATUSERROR
- Use an output parameter to indicate error to
caller - Caller must check for error and delete object
31Demo of Error Handling in Classes
32Encapsulation
- Good practice to keep data members protected or
private - Provide getter and setter routines to access
data members - Safe access
- Support read-only or write-only
- PROPERTY class members coming!
33Compiling Tips and Techniques
- Strong-typing only works if you compile running
compile-on-the-fly catches all errors at
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
34Compiling 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
35Compiling 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
36Recommended Coding Standards
- Always use packages in your type name
Acme.DAOrder - First node is your company name
- Class and Interface names use CamelCase starting
with uppercase letter - Interface names start with leading I
Acme.IList - Methods and data member use camelCase with
lowercase first letter - Follow rules for encapsulation, abstraction, and
delegation
37In Summary
- Object-oriented ABL supports standard OO design
patterns abstraction, encapsulation,
inheritance, polymorphism - OO functionality still coming
- Overloading
- Properties
- Error handling
- Remote Objects
- CLASS-GLOBAL (Static)
- Strongly-typed events
38Related Sessions
- DEV1 Introduction to ObjectOriented Language
Concepts and Programming in OpenEdge ABL - MOVE11 Using Classes and Procedures in OpenEdge
10
39Questions?
40Thank you foryour time
41(No Transcript)