450 likes | 550 Views
DEV-10: Object-oriented Language Constructs for the 4GL. Evan Bleicher Development Manager. Under Development. D I S C L A I M E R. D I S C L A I M E R.
E N D
DEV-10:Object-oriented Language Constructs for the 4GL Evan Bleicher Development Manager
Under Development D I S C L A I M E R D I S C L A I M E R • 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. DEV-10, Object-oriented 4GL Constructs
Agenda • OO Overview • Anatomy of a CLASS • Objects • Inheritance • Compiler changes • Interoperability DEV-10, Object-oriented 4GL Constructs
Object-Oriented Overview • Class – Data members and methods • Object – Runtime instance of a class • Object Reference – Strongly typed object handle • Typing – Type consistency enforced • Interface – Set of method definitions DEV-10, Object-oriented 4GL Constructs
Object-Oriented Overview • Inheritance – Reuse and specialize code • Super Class – Common features inherited by another class • Subclass – Inherits features from another class • Override – Derived class customized behavior Class: Order PRIVATE: orderNum AS INT CalculatePrice ( ) PROTECTED: CalculateTax ( ) PUBLIC: CreateOrder ( ) GetOrderTotal ( ) Class: InternalOrder PUBLIC: GetOrderTotal ( ) DEV-10, Object-oriented 4GL Constructs
Benefits of OO in the 4GL Programming Business • Code Reuse • Inheritance • Encapsulation • Strong typing • Invocation model • Productivity • Easy to develop • Maintenance • Robustness • Ease of use DEV-10, Object-oriented 4GL Constructs
Similarities betweenClasses and Procedures Classes Procedures • Procedure file • Define variables • Internal procedures • User defined functions • Code in main block • Super procedures • Class files • Data members • VOID methods • Other methods • Constructor • Inheritance DEV-10, Object-oriented 4GL Constructs
Agenda • OO Overview • Anatomy of a CLASS • Objects • Inheritance • Compiler changes • Interoperability DEV-10, Object-oriented 4GL Constructs
Anatomy of a Class CLASS <class-type> [options]: [ <data member> …] [ <constructor> ] [ <method> … ] [ <destructor> ] END [ CLASS ]. DEV-10, Object-oriented 4GL Constructs
CLASSStatement [package.]classname ProPath \acme \request \Order.cls \Order.r CLASS <class-type> [ INHERITS <super-class-type> ] [ IMPLEMENTS <interface-type> [, <interface-type> ]… ] [ FINAL ]: acme\request\Order.cls CLASS acme.request.Order: DEV-10, Object-oriented 4GL Constructs
Example:Defining a CLASS hierarchy acme\request\Order.cls CLASS acme.request.Order: END CLASS. acme\request\InternalOrder.cls CLASS acme.request.InternalOrder INHERITS acme.request.Order: END CLASS. DEV-10, Object-oriented 4GL Constructs
Data Members • New keyword added to existing DEFINE syntax • PRIVATE(default) • PROTECTED • PUBLIC • Defined outside of methods • Scoped to class • Define state an object DEV-10, Object-oriented 4GL Constructs
Example:Defining Data Members acme\request\Order.cls CLASS acme.request.Order: DEFINE PUBLIC VARIABLE ShipDate AS DATE. DEFINE PROTECTED TEMP-TABLE SalesRepTT FIELD RepName AS CHAR FIELD Region AS CHAR. DEFINE PRIVATE VARIABLE OrderNum AS INT. END CLASS. DEV-10, Object-oriented 4GL Constructs
Anatomy of a Method METHOD [PRIVATE | PUBLIC | PROTECTED ] [ FINAL] { VOID | <return-type> } <method-name> ( [ <parameter> [ ,<parameter> ]… ] ): <method-body> END [METHOD]. DEV-10, Object-oriented 4GL Constructs
Example:Defining Methods acme\request\Order.cls CLASS acme.request.Order: DEFINE PRIVATE VARIABLE OrderNum AS INTEGER. METHOD PUBLIC INTEGER GetOrderNum ( ): RETURN OrderNum. END METHOD. END CLASS. DEV-10, Object-oriented 4GL Constructs
Example:Defining Methods acme\request\Order.cls CLASS acme.request.Order: DEFINE PRIVATE VARIABLE OrderNum AS INTEGER. METHOD PUBLIC VOID SetOrderNum (INPUT ordNum AS INTEGER ): OrderNum = ordNum. END METHOD. END CLASS. DEV-10, Object-oriented 4GL Constructs
Anatomy of a Constructor CONSTRUCTOR [ PUBLIC | PROTECTED] <class-name> ( [ <parameter> [ ,<parameter> ]… ] ): <constructor-body> END [CONSTRUCTOR]. DEV-10, Object-oriented 4GL Constructs
Example:Defining Constructor acme\request\Order.cls CLASS acme.request.Order: CONSTRUCTOR PUBLIC Order ( ) : /* Initialize data members */ END CONSTRUCTOR. END CLASS. DEV-10, Object-oriented 4GL Constructs
Anatomy of a Destructor DESTRUCTOR [ PRIVATE ] <class-name> ( ): <destructor-body> END [DESTRUCTOR]. DEV-10, Object-oriented 4GL Constructs
Example:Defining Destructor acme\request\Order.cls CLASS acme.request.Order: DESTRUCTOR PRIVATE Order ( ) : /* Perform cleanup of resources. */ END DESTRUCTOR. END CLASS. DEV-10, Object-oriented 4GL Constructs
Anatomy of an Interface INTERFACE <interface-type>: [ <temp-table> | <ProDataSet> ] [ <method> …] END [INTERFACE]. DEV-10, Object-oriented 4GL Constructs
Example:Defining an Interface acme\navigation\support\IList.cls INTERFACE acme.navigation.support.IList: METHOD PUBLIC VOID Next ( ). METHOD PUBLIC VOID Prev ( ). METHOD PUBLIC VOID First ( ). METHOD PUBLIC VOID Last ( ). END INTERFACE. DEV-10, Object-oriented 4GL Constructs
Example:Implementing an Interface CLASS acme.request.InternalOrder INHERITS acme.request.Order IMPLEMENTS acme.navigation.support.IList: METHOD PUBLIC VOID Next ( ) : /* Implementation of Next Method */ END METHOD. /* Repeat for Prev, First and Last … */ END CLASS. acme\request\InternalOrder.cls DEV-10, Object-oriented 4GL Constructs
Agenda • OO Overview • Anatomy of a CLASS • Objects • Inheritance • Compiler changes • Interoperability DEV-10, Object-oriented 4GL Constructs
Instantiating an object • NEW statement • Creates an instance of the class • Strongly typed object reference • Causes constructor to be invoked • Execution of all constructors in hierarchy chain DEV-10, Object-oriented 4GL Constructs
NEW Statement DEFINE VARIABLE <object-ref > AS [ CLASS ] <class-type>. <object-ref > = NEW <class-type > ( <parameter> [ ,<parameter> ]… ) [ ON <server-handle> ] [ NO-ERROR ]. DEV-10, Object-oriented 4GL Constructs
Example:Instantiating an Object DEFINE VARIABLE rIntOrderObj AS CLASS acme.request.InternalOrder. rIntOrderObj = NEW acme.request.InternalOrder ( ). DEV-10, Object-oriented 4GL Constructs
Accessing Data Members & Methods • An Object Reference can access • PUBLIC Data Members • PUBLIC Methods • rIntOrderObj:shipDate • rIntOrderObj:GetOrderNum ( ) DEV-10, Object-oriented 4GL Constructs
Accessing Data Members & Methods • Within a class hierarchy • PUBLIC or PROTECTED Data Members • PUBLIC or PROTECTED Methods • SalesRepTT.RepName • protectedMethod ( ) • Within a class • PRIVATE Data Members • PRIVATE Methods • orderNum • CalculatePrice ( ) DEV-10, Object-oriented 4GL Constructs
Agenda • OO Overview • Anatomy of a CLASS • Objects • Inheritance • Compiler changes • Interoperability DEV-10, Object-oriented 4GL Constructs
Inheritance • Subclass inherits super class’ • PUBLIC & PROTECTED data members • PUBLIC & PROTECTED methods • Subclass can: • add additional capabilities • augment behavior of super class • override behavior of super class DEV-10, Object-oriented 4GL Constructs
Overriding Order • Overridden method must have same signature • To access any super class’ method use SUPER-CLASS: <method-name> • Always invoke method in most-derived object! METHOD VOID GetOrderTotal ( ): END METHOD. InternalOrder METHOD VOID GetOrderTotal ( ): SUPER-CLASS:GetOrderTotal ( ). END METHOD. DEV-10, Object-oriented 4GL Constructs
Example:Overriding METHOD PUBLIC DECIMAL GetOrderTotal ( ): /* Calculate total */ RETURN totalOrder. END METHOD. acme\request\Order.cls acme\request\InternalOrder.cls METHOD PUBLIC DECIMAL GetOrderTotal ( ): DEFINE VAR dTotal AS DECIMAL. dTotal = SUPER-CLASS:GetOrderTotal ( ). RETURN dTotal * dDiscount. END METHOD. DEV-10, Object-oriented 4GL Constructs
Example:Calling Overridden Method DEFINE VAR rIntOrderObj AS acme.request.InternalOrder. rIntOrderObj = NEW acme.request.InternalOrder ( ). rIntOrderObj:GetOrderTotal ( ). Order GetOrderTotal: RETURN total. InternalOrder GetOrderTotal: RETURN SUPER-CLASS: GetOrderTotal ( ) * discount. DEV-10, Object-oriented 4GL Constructs
Agenda • OO Overview • Anatomy of a CLASS • Objects • Inheritance • Compiler changes • Interoperability DEV-10, Object-oriented 4GL Constructs
Compiler changes • Two – pass compiler • Compile time validation of object reference • Validates • Methods • Parameters • Compiles all files in class hierarchy DEV-10, Object-oriented 4GL Constructs
Agenda • OO Overview • Anatomy of a CLASS • Objects • Inheritance • Compiler changes • Interoperability DEV-10, Object-oriented 4GL Constructs
InteroperabilityProcedures and Classes • Procedures • Can NEW a CLASS • Can DELETE an object • Invoke methods using object reference • Can pass object reference as a parameter • Classes • Can RUN a procedure • Can invoke internal procedure / udf using procedure handle DEV-10, Object-oriented 4GL Constructs
Integration with tools • New IDE • Procedure Editor • Procedure Window • Debugger DEV-10, Object-oriented 4GL Constructs
Future • Phased approach • Overloading • Arrays of object references • Available via Open Client • Improved Error Handling DEV-10, Object-oriented 4GL Constructs
In Summary • Standard OO concepts available in the 4GL • Built on top of existing 4GL constructs • Interoperability with Procedure / Functions DEV-10, Object-oriented 4GL Constructs
Questions? DEV-10, Object-oriented 4GL Constructs
Thank you for your time! DEV-10, Object-oriented 4GL Constructs