Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEV-12: Object-oriented Programming in OpenEdge® ABL

Similar presentations


Presentation on theme: "DEV-12: Object-oriented Programming in OpenEdge® ABL"— Presentation transcript:

1 DEV-12: Object-oriented Programming in OpenEdge® ABL
Evan Bleicher Senior Development Manager, Progress OpenEdge

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 DEV-12, Object-oriented Programming in OpenEdge ABL

3 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

4 CLASS Statement CLASS <class-type> [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. DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

6 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

7 Type Name Type defines Enable strong-typing
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 DEV-12, Object-oriented Programming in OpenEdge ABL

8 Example: Type Names DEF VAR myOrder AS CLASS Acme.Inv.Order.
DEF VAR myInternalOrder AS CLASS Acme.Inv.InternalOrder. DEF VAR myExternalOrder AS CLASS Acme.Inv.ExternalOrder. myOrder = NEW Acme.Inv.Order ( ). myInternalOrder = NEW Acme.Inv.InternalOrder ( ). myExternalOrder = NEW Acme.Inv.ExternalOrder ( ). DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

10 Example: Type 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 ( ). DEV-12, Object-oriented Programming in OpenEdge ABL

11 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

12 Methods Keywords defining methods Supports access modifiers
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 DEV-12, Object-oriented Programming in OpenEdge ABL

13 Overriding Method in subclass can specialize method in super class
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 SUPER:method-name ( ) DEV-12, Object-oriented Programming in OpenEdge ABL

14 Example: Overriding Acme\Inv\Order.cls OVERRIDE keyword
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 = SUPER:getOrderTotal ( ). RETURN dTotal * dDiscount. END METHOD. Pre / Post processing DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

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 ( ): DEV-12, Object-oriented Programming in OpenEdge ABL

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 = myOrder:getOrderTotal( ). Calls either Acme.Inv.InternalOrder or Acme.Inv.ExternalOrder getOrderTotal ( ) Super Class Reference DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

20 Example: Overloading No arguments One argument - integer
METHOD PUBLIC INTEGER getOrder ( ): END METHOD. METHOD PUBLIC INTEGER getOrder ( INPUT iCustNum AS INTEGER): INPUT cSalesRep AS CHARACTER): One argument - integer One argument - character DEV-12, Object-oriented Programming in OpenEdge ABL

21 Widening (10.1B) Object-oriented features are strongly-typed
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 DEV-12, Object-oriented Programming in OpenEdge ABL

22 Example: Widening 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). DEV-12, Object-oriented Programming in OpenEdge ABL

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 caller’s data type does not have to match exactly the callee’s data type Overloading looks for the best match Application design concern: May result in ambiguity error DEV-12, Object-oriented Programming in OpenEdge ABL

24 Example: Widening with Overloading
METHOD PUBLIC INTEGER updateSalesRecord ( INPUT dtTransDate AS DATETIME-TZ, INPUT szSalesRep AS CHARACTER): INPUT dtTransDate AS DATE, updateSalesRecord (INPUT myDate, INPUT “ABC”). updateSalesRecord (INPUT myDateTime, INPUT “ABC”). updateSalesRecord (INPUT myDateTimeTZ, INPUT “ABC”). DEV-12, Object-oriented Programming in OpenEdge ABL

25 Example: Widening with Overloading
METHOD PUBLIC INTEGER UpdateSalesRecord ( INPUT dtTransDate AS DATETIME-TZ, INPUT iSalesAmount AS INTEGER): INPUT dShipDate AS DATE, INPUT deUnitsSold AS DECIMAL): UpdateSalesRecord (INPUT myDate, INPUT myInt64). UpdateSalesRecord (INPUT myDateTime, INPUT myDecimal). UpdateSalesRecord (INPUT myDate, INPUT myInteger). Does not compile – Ambiguity error Does not compile – no match DEV-12, Object-oriented Programming in OpenEdge ABL

26 Overloading: Other 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 DEV-12, Object-oriented Programming in OpenEdge ABL

27 Raising Error (10.1B) Methods can raise error
RETURN ERROR [<error string>] Caller handles error condition NO-ERROR ON ERROR phrase Retrieve <error string> via RETURN-VALUE function DEV-12, Object-oriented Programming in OpenEdge ABL

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 = objA:methA( ) – objB:methB( ) * objC:methC( ). DEV-12, Object-oriented Programming in OpenEdge ABL

29 Example: Error in an Expression
myInt = objA:methA( ) – objB:methB( ) * objC:methC( ). If methA raises error, methB and methC are not invoked myInt’s value remains unchanged If methB raises error, methC is not invoked DEV-12, Object-oriented Programming in OpenEdge ABL

30 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

31 Object Instantiation Constructor of specified class is invoked on NEW
Constructor used to initialize data members Constructor must call super class’s constructor Via SUPER ( ) OpenEdge provides a call to the ‘default’ constructor One with no parameters Only if super class has no other constructor DEV-12, Object-oriented Programming in OpenEdge ABL

32 Example: Object Instantiation
Class A refD = NEW D (D’s params). Invokes D’s constructor Class B CONSTRUCTOR PUBLIC C (C’s params ): SUPER (B’s params). /* C’s constructor body */ END. Class C CONSTRUCTOR PUBLIC D (D’s params ): SUPER (C’s params). /* D’s constructor body */ END. Class D DEV-12, Object-oriented Programming in OpenEdge ABL

33 Overloading of Constructor
Classes can have multiple constructors Same rules as overloading for methods Parameters specified in NEW determine which constructor is invoked DEV-12, Object-oriented Programming in OpenEdge ABL

34 Example: Overloading One argument - Integer One argument - Character
No arguments One argument - Integer One argument - Character CONSTRUCTOR PUBLIC Order ( ): /* Constructor code goes here */ END CONSTRUCTOR. CONSTRUCTOR PUBLIC Order ( INPUT iCustNum AS INTEGER): INPUT cSalesRep AS CHARACTER): DEV-12, Object-oriented Programming in OpenEdge ABL

35 Raising Error (10.1B) Constructors can raise error
RETURN ERROR [<error string>] Caller handles error condition NO-ERROR ON ERROR phrase Object reference unchanged Destructor invoked for all classes in hierarchy whose constructor completed successfully DEV-12, Object-oriented Programming in OpenEdge ABL

36 Example: Raising Error in a Constructor
DEFINE VARIABLE refD AS CLASS D. refD = NEW D ( ) NO-ERROR. IF ERROR-STATUS:ERROR THEN MESSAGE “INSTANTIATION FAILED: “ RETURN-VALUE. Class A Class B Class C CONSTRUCTOR PUBLIC D (D’s params ): SUPER (C’s params). /* D’s constructor body */ RETURN ERROR “ret code 101”. END. Class D DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

38 Example: Object Deletion
Class A DELETE OBJECT refD. Invokes D’s Destructor Class B DESTRUCTOR PUBLIC C ( ): /* C’s destructor */ END. Class C DESTRUCTOR PUBLIC D ( ): /* D’s destructor */ END. Class D DEV-12, Object-oriented Programming in OpenEdge ABL

39 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

41 Example: Defining Property
DEFINE PUBLIC PROPERTY Salary AS DECIMAL GET ( ): /* Verify current user’s status */ RETURN Salary. END GET. PROTECTED SET (INPUT iVal AS DECIMAL): /* Is it within range? */ IF ival LT THEN Salary = ival. ELSE RETURN ERROR. END SET. DEV-12, Object-oriented Programming in OpenEdge ABL

42 Example: Accessing a Property
Same syntax as setting / retrieving a data member Can be used in expression EmployeeObj:Salary = newValue. DISPLAY EmployeeObj:Salary. DeptObj:Record (INPUT EmployeeObj:Name, INPUT EmployeeObj:Salary). DEV-12, Object-oriented Programming in OpenEdge ABL

43 Example 2: Defining 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. DEV-12, Object-oriented Programming in OpenEdge ABL

44 Example 3: Defining Property – not using default memory
DEFINE PUBLIC PROPERTY numUnits AS INTEGER GET ( ): /* Retrieve from temp-table – current value */ RETURN someTT:currentInventory. END GET. IF numRequested LT orderObj:numUnits THEN orderObj:processOrder(INPUT numRequested). ELSE ... DEV-12, Object-oriented Programming in OpenEdge ABL

45 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

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… DEV-12, Object-oriented Programming in OpenEdge ABL

47 Compiling Tips and Techniques
Add new method Compile 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 Call new method Recompile B E I C F J D G K H DEV-12, Object-oriented Programming in OpenEdge ABL

48 Compiling Tips and Techniques
Build procedures (make.p) Total files compiled: MULTI-COMPILE = FALSE: 25 MULTI-COMPILE = TRUE: 8 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 C D E F G H DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

50 Today’s Agenda Class Statement Type Names Methods Object Hierarchy
Properties Interface Class Compiler Enhancements Roadmap 10.1C and Beyond DEV-12, Object-oriented Programming in OpenEdge ABL

51 10.1A Class Interface Inheritance Overriding
Access mode for data members Strong type checking Compiler improvements DEV-12, Object-oriented Programming in OpenEdge ABL

52 10.1B USING Overloading Properties
Default access mode methods - PUBLIC Raising error from Constructor / Methods Compiler system handle changes DEV-12, Object-oriented Programming in OpenEdge ABL

53 Under Development D I S C L A I M E R
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 DEV-12, Object-oriented Programming in OpenEdge ABL

54 Targeted for 10.1C Structured Error Handling Statics
Similar to Try, Catch, Throw Statics Constructors, Data Members, Methods Character to Longchar widening NEW function DEV-12, Object-oriented Programming in OpenEdge ABL

55 Future Release Remote objects Strongly typed application events
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 DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

57 Additional Object-oriented Exchange Sessions
DEV-6: Getting Started with Object-oriented ABL Programming (Evan Bleicher) ARCH-7: A Class-based Implementation of the OERA (John Sadd) ARCH-9: Using Object-oriented ABL Features in N-Tier Environment (Mike Fechner) ARCH-12: Leveraging Design Patterns in ABL Applications (Phil Magnay) DEV-20: Using Classes and Procedures in OpenEdge 10.1B (Phil Magnay) DEV-12, Object-oriented Programming in OpenEdge ABL

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 DEV-12, Object-oriented Programming in OpenEdge ABL

59 Questions? DEV-12, Object-oriented Programming in OpenEdge ABL

60 Thank you for your time! DEV-12, Object-oriented Programming in OpenEdge ABL

61 DEV-12, Object-oriented Programming in OpenEdge ABL


Download ppt "DEV-12: Object-oriented Programming in OpenEdge® ABL"

Similar presentations


Ads by Google