Title: DEV1: Introduction to ObjectOriented Language Concepts and Programming in OpenEdge ABL
1DEV-1 Introduction to Object-Oriented Language
Concepts and Programming in OpenEdge ABL
Evan Bleicher
Senior Development Manager
2Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
3Under 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.
4Object-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
5Object-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
6Type - 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
7Benefits 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
8Object-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( )
9Object-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
10Object-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
11Inheritance 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
12Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
13Anatomy of a Class
- CLASS ltclass-typegt
- options
- ltdata membergt
- ltconstructorgt
- ltmethodgt
- ltdestructorgt
- END CLASS .
14CLASSStatement
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
15ExampleDefining a CLASS hierarchy
CLASS acme.request.Order END CLASS.
16Access 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
17Data 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
18ExampleDefining Data Members
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.
19Methods
- New keywords defining methods
- METHOD
- CONSTRUCTOR
- DESTRUCTOR
- Scoped to class
- Define behavior an object
20Anatomy of a Method
- METHOD PRIVATE PROTECTED PUBLIC
- options
- VOID ltreturn-typegt
- ltmethod-namegt
- ( ltparametergt ,ltparametergt )
- ltmethod-bodygt
- END METHOD.
21ExampleDefining Methods (like a function)
CLASS acme.request.Order DEFINE PRIVATE
VARIABLE OrderNum AS INTEGER. METHOD PUBLIC
INTEGER GetOrderNum ( ) RETURN OrderNum.
END METHOD. END CLASS.
22ExampleDefining Methods (like a procedure)
CLASS acme.request.Order DEFINE PRIVATE
VARIABLE OrderNum AS INTEGER. METHOD PUBLIC
VOID SetOrderNum (INPUT ordNum AS
INTEGER ) OrderNum ordNum. END
METHOD. END CLASS.
23Anatomy of a Constructor
package.classname
- CONSTRUCTOR PUBLIC PROTECTED
- ltclass-namegt
- ( ltparametergt ,ltparametergt )
- ltconstructor-bodygt
- END CONSTRUCTOR.
24ExampleDefining Constructor
CLASS acme.request.Order CONSTRUCTOR PUBLIC
Order ( ) / Initialize data members /
END CONSTRUCTOR. END CLASS.
25Anatomy of a Destructor
package.classname
- DESTRUCTOR PUBLIC
- ltclass-namegt ( )
- ltdestructor-bodygt
- END DESTRUCTOR.
26ExampleDefining Destructor
CLASS acme.request.Order DESTRUCTOR PUBLIC
Order ( ) / Perform cleanup of
resources. / END DESTRUCTOR. END CLASS.
27Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
28NEW Statement
- DEFINE VARIABLE ltobject-ref gt AS
- CLASS ltclass-typegt.
- ltobject-ref gt NEW ltclass-type gt
- ( ltparametergt ,ltparametergt )
- NO-ERROR .
29ExampleInstantiating a class
DEFINE VARIABLE rIntOrderObj AS CLASS
acme.request.InternalOrder. rIntOrderObj
NEW acme.request.InternalOrder ( ).
New runs class constructor Instantiating the
object
30Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
31Anatomy of an Interface
- INTERFACE ltinterface-typegt
- lttemp-tablegt ltprodatasetgt
- ltmethod prototypegt
- END INTERFACE.
32ExampleDefining 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.
33ExampleImplementing 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.
34Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
35Inheritance
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
36Overriding
- 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.
37ExampleOverriding
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.
38Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
39Polymorphism
- 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
40Polymorphism Example
Order
METHOD GetCredit( ) credit CalculateCredit(
).
InternalOrder
METHOD Overload GetCredit ( ) credit -1.
/unlimited/
ExternalOrder
METHOD GetCredit( ) credit SUPERGetCredit(
) factor.
41Polymorphism - 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( )
42Delegation
- 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
43Delegation 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.
44Agenda Slide
- Object-oriented foundation
- ABL main constructs
- Classes
- Objects
- Interface
- Inheritance
- Advanced features
- Other topics
45Compiler changes
- Two pass compiler
- Compile time validation of object reference
- Validates
- Methods
- Parameters
- Compiles all files in class hierarchy
46InteroperabilityProcedures 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
47Integration with tools
- OpenEdge Architect
- Procedure Editor
- Procedure Window
- Debugger
- No support for classes in Appbuilder Section
Editor
4810.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
49Future 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
50In Summary
- Standard OO concepts available in the ABL
- Built on top of existing ABL constructs
- Interoperability with Procedure / Functions
- More to come
51Questions?
52Thank you foryour time
53(No Transcript)