Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEV-6: Advanced Object-Oriented Programming in the ABL Evan Bleicher Senior Development Manager Shelley Chase

Similar presentations


Presentation on theme: "DEV-6: Advanced Object-Oriented Programming in the ABL Evan Bleicher Senior Development Manager Shelley Chase"— Presentation transcript:

1 DEV-6: Advanced Object-Oriented Programming in the ABL Evan Bleicher bleicher@progress.com Senior Development Manager Shelley Chase schase@progress.com Architect

2 © 2006 Progress Software Corporation2 DEV-6 Advanced Object-oriented Programming in the ABL D I S C L A I M E R 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. D I S C L A I M E R

3 © 2006 Progress Software Corporation3 DEV-6 Advanced Object-oriented Programming in the ABL Agenda  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

4 © 2006 Progress Software Corporation4 DEV-6 Advanced Object-oriented Programming in the ABL Order Entry System Object Model “ Business Entity” Interface between DA layer and Presentation / Integration “Data Access Object” Interface to Data Store Use OpenEdge® Reference Architecture Presentation Business Services Data Access Data Sources Common Infrastructure Enterprise Services

5 © 2006 Progress Software Corporation5 DEV-6 Advanced Object-oriented Programming in the ABL Order Entry Object Model - Handout Inherits CLASS Acme.BusinessEntity DEF VAR rDataObject AS CLASS IDataAccess METHOD VOID fetchWhere ( ) METHOD VOID saveChanges ( ) CLASS Acme.BEOrder INHERITS Acme.BusinessEntity METHOD VOID processOrder ( ) … Inherits CLASS Acme.BEInternalOrder INHERITS Acme.BEOrder DEF VAR invoiceNum AS INT METHOD VOID OVERRIDE processOrder ( ) … CLASS Acme.BEExternalOrder INHERITS Acme.BEOrder DEF VAR crossDept AS INT METHOD VOID OVERRIDE processOrder ( ) … Inherits CLASS Acme.DAOrderSuper PROTECTED TEMP-TABLE ttOline PROTECTED TEMP-TABLE ttOrder PROTECTED DATASET dsOrder … INTERFACE Acme.IDataAccess METHOD LONGCHAR selectRecords ( … ) Implements CLASS Acme.DAItem IMPLEMENTS Acme.IDataAccess, Acme.IList … CLASS Acme.DAOrder INHERITS Acme.DAOrderSuper IMPLEMENTS Acme.IDataAccess, Acme.IList METHOD LONGCHAR selectRecords ( … ) METHOD NextRecord ( ) METHOD PrevRecord ( ) METHOD VOID postOlineFill ( … ) METHOD VOID postDSFill ( … ) Implements INTERFACE Acme.IList METHOD nextRecord ( ) METHOD prevRecord ( ) …

6 © 2006 Progress Software Corporation6 DEV-6 Advanced Object-oriented Programming in the ABL Order Entry Object Model – Data Access Layer CLASS Acme.DAOrderSuper CLASS Acme.DAItem INTERFACE Acme.IList Implements CLASS Acme.DAOrder Inherits INTERFACE Acme.IDataAccess Implements Data Access Interface Navigation Interface Super Order Class Specific Order Class Specific Item Class PROTECTED TEMP-TABLE ttOline PROTECTED TEMP-TABLE ttOrder PROTECTED DATASET dsOrder METHOD LONGCHAR selectRecords (…) METHOD LONGCHAR selectRecords (…) METHOD LONGCHAR selectRecords (…) Implements

7 © 2006 Progress Software Corporation7 DEV-6 Advanced Object-oriented Programming in the ABL Order Entry Object Model – Business Servicing LayerCLASSAcme.BusinessEntity CLASSAcme.BEOrder CLASSAcme.BEInternalOrderCLASSAcme.BEExternalOrder Inherits Business Entity Class Order Class Specific Internal Order Class Specific External Order Class DEF VAR rDataObject AS CLASS Acme.IDataAccess METHOD VOID fetchWhere ( ) METHOD VOID saveChanges ( ) METHOD VOID processOrder( ) METHOD OVERRIDE VOID processOrder ( ) METHOD OVERRIDE VOID processOrder ( )

8 © 2006 Progress Software Corporation8 DEV-6 Advanced Object-oriented Programming in the ABL Physical Architecture of A Class Hierarchy COMPILE Acme/BEExternalOrder.cls SAVE. Inherits / Acme / BusinessEntity.cls / Acme / BusinessEntity.cls / Acme / BEOrder.cls / Acme / BEOrder.cls / Acme / BEExternalOrder.cls / Acme / BEExternalOrder.cls

9 © 2006 Progress Software Corporation9 DEV-6 Advanced Object-oriented Programming in the ABL COMPILE Physical Architecture of A Class Hierarchy COMPILE Acme/BEExternalOrder.cls SAVE. Inherits / Acme / BusinessEntity.cls / Acme / BusinessEntity.cls / Acme / BEOrder.cls / Acme / BEOrder.cls / Acme / BEExternalOrder.cls / Acme / BEExternalOrder.cls

10 © 2006 Progress Software Corporation10 DEV-6 Advanced Object-oriented Programming in the ABL Physical Architecture of A Class Hierarchy COMPILE Acme/BEExternalOrder.cls SAVE. Inherits Digest: Inherits: Implements: … Class r-code Data / Acme / BusinessEntity.cls / Acme / BusinessEntity.cls / Acme / BEOrder.cls / Acme / BEOrder.cls / Acme / BEExternalOrder.cls / Acme / BEExternalOrder.cls / Acme / BEOrder.r 5678 Acme/BusinessEntity, 1234 None / Acme / BusinessEntity.r 1234 None / Acme / BEExternalOrder.r 9000 Acme/BEOrder, 5678 None

11 © 2006 Progress Software Corporation11 DEV-6 Advanced Object-oriented Programming in the ABL Agenda  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

12 © 2006 Progress Software Corporation12 DEV-6 Advanced Object-oriented Programming in the ABL Abstract (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

13 © 2006 Progress Software Corporation13 DEV-6 Advanced Object-oriented Programming in the ABL Choosing 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

14 © 2006 Progress Software Corporation14 DEV-6 Advanced Object-oriented Programming in the ABL Abstract Programming Using Interfaces  Define an interface Common methods put in interface Implementer must provide code for methods INTERFACE Acme.IDataAccess CLASS Acme.DAOrder CLASS Acme.DAItem Implements METHOD LONGCHAR selectRecords (…) METHOD LONGCHAR selectRecords (…) METHOD LONGCHAR selectRecords (…) Interface Implementer

15 © 2006 Progress Software Corporation15 DEV-6 Advanced Object-oriented Programming in the ABL Abstract Programming Using Super Classes  Define a super class Common methods including code put in super class Optionally, subclass can override common code CLASSAcme.BEOrder CLASSAcme.BEInternalOrderCLASSAcme.BEExternalOrder METHOD OVERRIDE VOID processOrder ( ) METHOD OVERRIDE VOID processOrder ( ) METHOD VOID processOrder ( ) Super Class Subclass

16 © 2006 Progress Software Corporation16 DEV-6 Advanced Object-oriented Programming in the ABL Abstract 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 = rDataObject:selectRecords (…). … CLASS Acme.BEOrder: CONSTRUCTOR BEOrder ( ): /* Create Order data object assign to super class reference*/ rDataObject = NEW Acme.DAOrder ( ). lcVar2 = rDataObject:fetchWhere (…). …

17 © 2006 Progress Software Corporation17 DEV-6 Advanced Object-oriented Programming in the ABL Demo of Abstract Programming

18 © 2006 Progress Software Corporation18 DEV-6 Advanced Object-oriented Programming in the ABL Multiple Inheritance Using Interfaces  Some older OO languages support multiple inheritance  Newer OO languages support multiple APIs using interfaces – class inheritance is single CLASSAcme.DAOrder INTERFACE Acme.IDataAccess INTERFACE Acme.IList Implements METHOD LONGCHAR selectRecords (…) METHOD NextRecord ( ) METHOD PrevRecord ( ) METHOD LONGCHAR selectRecords (…) METHOD NextRecord ( ) METHOD PrevRecord ( )

19 © 2006 Progress Software Corporation19 DEV-6 Advanced Object-oriented Programming in the ABL Agenda  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

20 © 2006 Progress Software Corporation20 DEV-6 Advanced Object-oriented Programming in the ABL Datasets 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.Object Automatically upcast when put into column CAST column value to subclass before use

21 © 2006 Progress Software Corporation21 DEV-6 Advanced Object-oriented Programming in the ABL Using 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.

22 © 2006 Progress Software Corporation22 DEV-6 Advanced Object-oriented Programming in the ABL Protected 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 CLASS Acme.DAOrderSuper CLASS Acme.DAOrder Inherits PROTECTED TEMP-TABLE ttOline PROTECTED TEMP-TABLE ttOrder PROTECTED DATASET dsOrder FOR EACH ttOrder: DISPLAY ttOrder.CustomerName

23 © 2006 Progress Software Corporation23 DEV-6 Advanced Object-oriented Programming in the ABL ProDataSet Event Handlers  Callbacks can be methods as well as internal procedures  Protected datasets can have handlers in subclass CLASS Acme. DAOrderSuper CLASS Acme.DAOrder Inherits /* Set callback in subclass for dataset in super class */ hDSOrder = dsOrder:HANDLE. hDSOrder:SET-CALLBACK (“AFTER-FILL”, “postDSFill”). … METHOD VOID postDSFill (DATASET dsOrder). …

24 © 2006 Progress Software Corporation24 DEV-6 Advanced Object-oriented Programming in the ABL Demo of Datasets and Temp-Tables

25 © 2006 Progress Software Corporation25 DEV-6 Advanced Object-oriented Programming in the ABL Agenda  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

26 © 2006 Progress Software Corporation26 DEV-6 Advanced Object-oriented Programming in the ABL Debugging 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

27 © 2006 Progress Software Corporation27 DEV-6 Advanced Object-oriented Programming in the ABL Using SUPER in Classes  Use SUPER ( ) to call super class constructor Only valid in constructor Must be first line if present  Use SUPER:method-name ( ) to call a method higher in the class hierarchy Valid in constructor, destructor, methods Must specify method-name (unlike procedures)

28 © 2006 Progress Software Corporation28 DEV-6 Advanced Object-oriented Programming in the ABL AppServer Running with Classes on an AppServer  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 Remote classes cannot be accessed from client ClientAppServer Data Client Data Dispatch.p RUN dispatch.p SET h. RUN getData (myTT) in h. Dataset / Temp-table Data Dataset / Temp-table Data Dataset / Temp-table

29 © 2006 Progress Software Corporation29 DEV-6 Advanced Object-oriented Programming in the ABL Error Handling  RETURN ERROR not allowed in classes  Options: 1.Use output parameter or return type 2.Use STOP mechanism  Improved error handling coming!

30 © 2006 Progress Software Corporation30 DEV-6 Advanced Object-oriented Programming in the ABL Options for Handling Errors in Constructor 1.Constructor handles error –Run DELETE THIS-OBJECT in constructor  Automatically runs destructors for any successful constructors in hierarchy –Caller checks object reference for unknown 3.Use an output parameter to indicate error to caller –Caller must check for error and delete object 2.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-STATUS:ERROR

31 © 2006 Progress Software Corporation31 DEV-6 Advanced Object-oriented Programming in the ABL Demo of Error Handling in Classes

32 © 2006 Progress Software Corporation32 DEV-6 Advanced Object-oriented Programming in the ABL Encapsulation  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!

33 © 2006 Progress Software Corporation33 DEV-6 Advanced Object-oriented Programming in the ABL Compiling 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…

34 © 2006 Progress Software Corporation34 DEV-6 Advanced Object-oriented Programming in the ABL Call new method Recompile Add new method Compile 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 BE F K J H GD C I

35 © 2006 Progress Software Corporation35 DEV-6 Advanced Object-oriented Programming in the ABL Compiling Tips and Techniques  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 Total files compiled: MULTI-COMPILE = FALSE:25 MULTI-COMPILE = TRUE:8 A B EFHG DC Build procedures (make.p)

36 © 2006 Progress Software Corporation36 DEV-6 Advanced Object-oriented Programming in the ABL Recommended 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

37 © 2006 Progress Software Corporation37 DEV-6 Advanced Object-oriented Programming in the ABL In 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

38 © 2006 Progress Software Corporation38 DEV-6 Advanced Object-oriented Programming in the ABL Related Sessions  DEV–1: Introduction to Object–Oriented Language Concepts and Programming in OpenEdge ABL  MOVE–11: Using Classes and Procedures in OpenEdge 10

39 © 2006 Progress Software Corporation39 DEV-6 Advanced Object-oriented Programming in the ABL Questions?

40 © 2006 Progress Software Corporation40 DEV-6 Advanced Object-oriented Programming in the ABL Thank you for your time

41 © 2006 Progress Software Corporation41 DEV-6 Advanced Object-oriented Programming in the ABL


Download ppt "DEV-6: Advanced Object-Oriented Programming in the ABL Evan Bleicher Senior Development Manager Shelley Chase"

Similar presentations


Ads by Google