DEV1: Introduction to ObjectOriented Language Concepts and Programming in OpenEdge ABL - PowerPoint PPT Presentation

1 / 53
About This Presentation
Title:

DEV1: Introduction to ObjectOriented Language Concepts and Programming in OpenEdge ABL

Description:

DEFINE VARIABLE object-ref AS [ CLASS ] class-type . object-ref = NEW class-type ... DEFINE VAR dTotal AS DECIMAL. dTotal = SUPER:GetOrderTotal ... – PowerPoint PPT presentation

Number of Views:107
Avg rating:3.0/5.0
Slides: 54
Provided by: PSC64
Category:

less

Transcript and Presenter's Notes

Title: DEV1: Introduction to ObjectOriented Language Concepts and Programming in OpenEdge ABL


1
DEV-1 Introduction to Object-Oriented Language
Concepts and Programming in OpenEdge ABL
Evan Bleicher
Senior Development Manager
2
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

3
Under 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.

4
Object-oriented Principles
  • Abstraction
  • Focus on public view, commonalities
  • Define public contract (API)
  • Encapsulation
  • Hide implementation details
  • Package data and methods together
  • Hierarchies
  • Build new objects by combining or extending other
    objects

5
Object-oriented Constructs Type
A Type is a definition
  • A Type defines the state and behavior
  • Identifies inheritance relationships with other
    types
  • No concern for implementation
  • Enables strong-typing
  • Early binding - types determined at compile time
  • Type-consistency enforced at compile time and
    runtime

6
Type - Example
  • Types
  • Order
  • InternalOrder
  • Subtype of Order
  • ExternalOrder
  • Subtype of Order

Order
is a
is a
ExternalOrder
InternalOrder
A subtype can appear anywhere a super type is
expected
7
Benefits of Types (Strong-Typing)
  • Compile time checking for type consistency
  • myObj mySubObject. (must be subtype)
  • myObjmethod(). (validates signature)
  • Results in safer code, with fewer bugs because
    all code paths checked at compile time

8
Object-oriented Constructs Class
A Class implements a Type
Class Order
  • A Class defines and implements a user-defined
    type
  • A Class is a template (blueprint) for an object
  • Data
  • Methods
  • Relationships to other classes

orderNum AS INT custNum AS INT CalculateTotalP
rice( )
Methods Data
CreateOrder( ) UpdateOrder( ) GetOrderTotal(
) Next( )
9
Object-oriented Constructs Object
An Object is an instance of a Class
  • An Object is created at runtime
  • Maintains independent state in data members
  • Code shared among object instances
  • The term Object is often used to refer to both
    classes and instances

10
Object-oriented Constructs Interface
An Interface implements a Type
  • An Interface is a collection of method
    definitions for a set of behaviors a
    contract
  • No implementation provided
  • A Class can implement an interface
  • Must implement all methods in the interface
  • Behavior can be specialized
  • Compiler validates implementation of interface

11
Inheritance and Method Overriding
  • Method overriding used to specialize behavior
  • Subclass may override a method in its super class
    (hierarchy)
  • Method signatures must match
  • Overriden method can
  • Completely override behavior of super class
  • Augment behavior by providing its own behavior
    and calling super class method

12
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

13
Anatomy of a Class
  • CLASS ltclass-typegt
  • options
  • ltdata membergt
  • ltconstructorgt
  • ltmethodgt
  • ltdestructorgt
  • END CLASS .

14
CLASSStatement
package.classname
  • CLASS ltclass-typegt
  • INHERITS ltsuper-class-typegt
  • IMPLEMENTS ltinterface-typegt
  • , ltinterface-typegt
  • options

ProPath \acme \request
\Order.cls \Order.r

File name acme\request\Order.cls CLASS
acme.request.Order
15
ExampleDefining a CLASS hierarchy
  • acme\request\Order.cls

CLASS acme.request.Order END CLASS.
16
Access Levels for Class Members
  • PRIVATE members available
  • Only within the class
  • PROTECTED members available
  • Within the class
  • Within the class hierarchy
  • PUBLIC members available
  • Within the class
  • Within the class hierarchy
  • To users outside the class

Order
PRIVATE PROTECTED PUBLIC
17
Data Members
  • Access mode added to existing DEFINE syntax
  • PRIVATE (default)
  • PROTECTED (not for visual widgets)
  • PUBLIC (limited to variables / no extents)
  • Defined outside of methods
  • Scoped to class
  • Define state an object

18
ExampleDefining Data Members
  • acme\request\Order.cls

CLASS acme.request.Order DEFINE PRIVATE
VARIABLE OrderNum AS INTEGER. DEFINE PROTECTED
TEMP-TABLE SalesRepTT FIELD RepName AS
CHARACTER FIELD Region AS CHARACTER.
DEFINE PUBLIC VARIABLE ShipDate AS DATE. END
CLASS.
19
Methods
  • New keywords defining methods
  • METHOD
  • CONSTRUCTOR
  • DESTRUCTOR
  • Scoped to class
  • Define behavior an object

20
Anatomy of a Method
  • METHOD PRIVATE PROTECTED PUBLIC
  • options
  • VOID ltreturn-typegt
  • ltmethod-namegt
  • ( ltparametergt ,ltparametergt )
  • ltmethod-bodygt
  • END METHOD.

21
ExampleDefining Methods (like a function)
  • acme\request\Order.cls

CLASS acme.request.Order DEFINE PRIVATE
VARIABLE OrderNum AS INTEGER. METHOD PUBLIC
INTEGER GetOrderNum ( ) RETURN OrderNum.
END METHOD. END CLASS.
22
ExampleDefining Methods (like a procedure)
  • 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.
23
Anatomy of a Constructor
package.classname
  • CONSTRUCTOR PUBLIC PROTECTED
  • ltclass-namegt
  • ( ltparametergt ,ltparametergt )
  • ltconstructor-bodygt
  • END CONSTRUCTOR.

24
ExampleDefining Constructor
  • acme\request\Order.cls

CLASS acme.request.Order CONSTRUCTOR PUBLIC
Order ( ) / Initialize data members /
END CONSTRUCTOR. END CLASS.
25
Anatomy of a Destructor
package.classname
  • DESTRUCTOR PUBLIC
  • ltclass-namegt ( )
  • ltdestructor-bodygt
  • END DESTRUCTOR.

26
ExampleDefining Destructor
  • acme\request\Order.cls

CLASS acme.request.Order DESTRUCTOR PUBLIC
Order ( ) / Perform cleanup of
resources. / END DESTRUCTOR. END CLASS.
27
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

28
NEW Statement
  • DEFINE VARIABLE ltobject-ref gt AS
  • CLASS ltclass-typegt.
  • ltobject-ref gt NEW ltclass-type gt
  • ( ltparametergt ,ltparametergt )
  • NO-ERROR .

29
ExampleInstantiating a class
DEFINE VARIABLE rIntOrderObj AS CLASS
acme.request.InternalOrder. rIntOrderObj
NEW acme.request.InternalOrder ( ).
New runs class constructor Instantiating the
object
30
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

31
Anatomy of an Interface
  • INTERFACE ltinterface-typegt
  • lttemp-tablegt ltprodatasetgt
  • ltmethod prototypegt
  • END INTERFACE.

32
ExampleDefining 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.
33
ExampleImplementing an Interface
  • acme\request\InternalOrder.cls

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.
34
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

35
Inheritance
Super Class
Relationship between Classes
  • Super Class (Base class)
  • Provides common functionality and data members
  • Subclass (Derived class)
  • Inherits public and protected members from the
    super class
  • Can extend or change behavior of super class by
    overriding methods


Super Class
Subclass
36
Overriding
  • Overridden method must have same signature
  • To access any super class method use
  • SUPERmethod-name
  • Unlike SUPER in procedures
  • Runtime invokes method in most-derived object!

Order

METHOD VOID GetOrderTotal ( ) END METHOD.
InternalOrder
METHOD OVERRIDE VOID GetOrderTotal ( ) /
Optional pre-processing /
SUPERGetOrderTotal ( ). / Optional post
processing / END METHOD.
37
ExampleOverriding
  • acme\request\Order.cls

METHOD PUBLIC DECIMAL GetOrderTotal ( ) /
Calculate total / RETURN totalOrder. END
METHOD.
acme\request\InternalOrder.cls
METHOD PUBLIC OVERRIDE DECIMAL GetOrderTotal (
) DEFINE VAR dTotal AS DECIMAL. dTotal
SUPERGetOrderTotal ( ). RETURN dTotal
dDiscount. END METHOD.
38
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

39
Polymorphism
  • Execution of an overridden method in a subclass
    from a reference to a super class
  • superclassmethod( )
  • 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 at runtime

40
Polymorphism Example
Order
METHOD GetCredit( ) credit CalculateCredit(
).
InternalOrder
METHOD Overload GetCredit ( ) credit -1.
/unlimited/
ExternalOrder
METHOD GetCredit( ) credit SUPERGetCredit(
) factor.
41
Polymorphism - Example continued
Super Class Reference
DEFINE myOrder AS CLASS Order. if (bInternalCust
TRUE) myOrder NEW InternalOrder( ). else
myOrder NEW ExternalOrder( ). myOrderGetCred
it( ).
Calls InternalOrderGetCredit( ) or
ExternalOrderGetCredit( )
42
Delegation
  • Delegation is the use of other objects
    within a class
  • Class forwards method calls to the
    contained object
  • Class wraps the delegate object
  • Creates an instance of the object
  • Defines a stub method for any referenced
    methods that should be public
  • No access to protected or private members

43
Delegation Example
  • Class Order references a ShipInfo object

ShipInfo
Order
Id AS INT Shipdate AS DATE Promisedate AS
DATE Method Public SetDate( ) Method
Public GetDate( )
m_Ship AS ShipInfo. Constructor Order
m_Ship NEW ShipInfo ( ). Method Public
GetShipDate ( ) m_ShipGetDate.
44
Agenda Slide
  • Object-oriented foundation
  • ABL main constructs
  • Classes
  • Objects
  • Interface
  • Inheritance
  • Advanced features
  • Other topics

45
Compiler changes
  • Two pass compiler
  • Compile time validation of object reference
  • Validates
  • Methods
  • Parameters
  • Compiles all files in class hierarchy

46
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

47
Integration with tools
  • OpenEdge Architect
  • Procedure Editor
  • Procedure Window
  • Debugger
  • No support for classes in Appbuilder Section
    Editor

48
10.1A Class Limitations
  • Limited support for reflection
  • No dynamic run (call) support
  • No support for PUBLISH / SUBSCRIBE
  • Cannot expose a class as WebService
  • Cannot ProxyGen a class
  • Limited native error handling support
  • Cannot NEW a class over an AppServer boundary

49
Future Enhancements
  • Support for Overloading of Methods, Constructor
  • Default access mode (PUBLIC) for Methods,
    Constructor and Destructor
  • Support for Properties
  • Data Member with defined Getter and Setter
  • Support for unqualified class name
  • Abstract classes and methods
  • Arrays of classes
  • Reflection
  • Remote object

50
In Summary
  • Standard OO concepts available in the ABL
  • Built on top of existing ABL constructs
  • Interoperability with Procedure / Functions
  • More to come

51
Questions?
52
Thank you foryour time
53
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com