Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenEdge® Object-oriented ABL

Similar presentations


Presentation on theme: "OpenEdge® Object-oriented ABL"— Presentation transcript:

1 OpenEdge® Object-oriented ABL
April 2014 Shelley Chase, Senior Architect Progress

2 Object-oriented programming in ABL (OOABL)
Introduced in 2007 with OE Release 10 Interoperates with procedures Procedures can call classes; classes can call procedures Same ABL logic in both New features implemented in OOABL When possible – already have enough keywords  Easy to consume – usage is very similar to persistent procedures GUI for .NET uses OOABL Use .NET classes to build rich desktop applications Use .NET classes for functionality not in ABL

3 Why should I Use Object-oriented (OO) programming?
Clean-er, “bug-free” code Compile-time validation for programming errors beyond syntax Tooling: Content-assist based on object definition Encapsulation and easier code reuse Protection levels identify external interface Common code in “super” class – seen at compilation Customize behavior without changing original code Most modern programming languages use OO concepts You can use words like “factory”, “instantiation”, “inheritance” and polymorphism (and know what they mean)

4 OO Programming Basics Functionality centered around “objects”
Type: definition of API and relationships with other Types Class: code represents data and behavior; implements a Type Object: runtime instance of a Class Other basic features Class members – constructors, destructors, methods, data

5 OO Definition: Type Type: Meta-data for a class
Data members – variable and properties (getter and setter) Method signatures – API for the class Logic is not part of the type Identifies relationships with other Types Inheritance from other Types Implement an Interface (special Type)

6 OO Definition: Class Class: ABL file with a .cls extension
Constructor called when class instantiated – place to do initialization Destructor called when class is deleted – place to do cleanup Methods are just like procedures and user-defined functions Variables represent the state of the object Properties wrap variables with a getter and setter Implemented in a class file (.cls) Compiles to .r just like procedures; can be put into PL files Similar to a persistent procedure

7 Sample OOABL Class – Starts with Type Definition
class Calculator: define variable total AS decimal NO-UNDO. constructor public Calculator( ): total = 0. end constructor. method void Add(iNum1 as integer, iNum2 as integer): total = iNum1 + iNum2. message total view-as alert-box. end method. end class. Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

8 Sample OOABL Class – Constructor
class Calculator: define variable total AS decimal NO-UNDO. constructor public Calculator( ): total = 0. end constructor. method void Add(iNum1 as integer, iNum2 as integer): total = iNum1 + iNum2. message total view-as alert-box. end method. end class. Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

9 Sample OOABL Class – Method
class Calculator: define variable total AS decimal NO-UNDO. constructor public Calculator( ): total = 0. end constructor. method void Add(iNum1 as integer, iNum2 as integer): total = iNum1 + iNum2. message total view-as alert-box. end method. end class. Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

10 OO Definition: Object Object: A running instance of a class
Object reference used to access instance – “strongly-typed” handle Creating the object runs the constructor – like block 0 of a persistent proc Each instance keeps context in data members Deleting the object runs the destructor Similar to a persistent procedure Run foo.p persistent set fooHandle. /* Create instance of a class */ define variable theCalculator as Calculator( ). theCalculator = new Calculator( ).

11 OO Definition: Method Method: business logic
Run by calling method on object reference Signature is strongly-typed Parameters checked at compile-time Similar to calling an internal proc or user-defined function Run myProc in fooHandle. /* Call Add method of the class */ /* total = iNum1 + iNum */ /* message total view-as alert-box */ theCalculator = new Calculator( ). theCalculator:Add(3, 4).

12 OO Definition: Variable
Variable: defines the state of the object instance Defined outside of methods (not global) Use DEFINE syntax with new access levels PRIVATE PROTECTED PUBLIC Accessed through object reference /* Access total variable of Calculator */ theCalculator = new Calculator( ). message theCalculator:total view-as alert-box. Private, which is the default, means that the data members can be accessed in the class file that defines it. Define statements that allow you to define a variables, buffer, temp-table, query, dataset, data-source Browse, Button, Frame, Image, Menu, Rectangle, Stream, Sub-menu, Work-table can be made private (Evan which defines are NOT listed here!) Protected data members can be accessed in the class file that defines it and in a class file that inherits from this class. Variables and buffer, temp-table, query, dataset, data-source Public variables can be accessed in the class file that defines it, in a class file that inherits from this class or a procedure or class that instantiates a class. variables only All methods within the class file can access all data members

13 OO Definition: Properties
Variable: defines the state of the object instance Defined outside of methods (not global) Includes variable definition plus GET and SET methods Can validate values before setting variable Read-only = GET and private SET class Calculator: define property total AS decimal NO-UNDO GET private SET. end class.

14 Questions Type Class Object Class members Constructor Destructor
Method Variable Property

15 OO Programming Using Types
Functionality centered around relationships Interface Type definition without implementation Inheritance Relationships between Types Override Customize behavior Polymorphism “Cool trick” Abstract class Part Class, part Interface Package Namespace for grouping

16 Definition: Interface
Special type of Class that has no code Basically a Class with only Type information: Data and Methods Defines a contract (API) Any class that implements the interface must code all methods Used when behavior must be specialized Compiler validates implementation of interface Interface iBaseCalculator: method void Subtract(iNum1 as integer, iNum2 as integer). method void Add(iNum1 as integer, iNum2 as integer). end interface.

17 Sample OOABL Class – Using an Interface
class Calculator implements iBaseCalculator: define variable total AS decimal initial 0 NO-UNDO. method void Add(iNum1 as integer, iNum2 as integer): total = iNum1 + iNum2. message total view-as alert-box. end method. method void Subtract(iNum1 as integer, iNum2 as integer): total = iNum1 - iNum2. end class. Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

18 Sample OOABL Class – Compile time Validation
class Calculator implements iBaseCalculator: define variable total AS decimal initial 0 NO-UNDO. method void Add(iNum1 as integer, iNum2 as integer): total = iNum1 + iNum2. message total view-as alert-box. end method. method void Subtract(iNum1 as integer, iNum2 as integer): total = iNum1 - iNum2. end class. Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

19 Definition: Inheritance
Inheritance: defines relationships among classes Super class – common data and functionality that can be shared by classes Subclass – specialized class that inherits from a Super class Inherits public & protected data members and methods Can add additional data and methods Override can augment OR override super class behavior OOABL super class All Types implicitly inherit from this super class Progress.Lang.Object

20 Sample OOABL Class – Inheritance
class AdvancedCalculator inherits Calculator: /* Inherits data members and methods from Calculator */ /* Extend the class with a new method */ method void Multiply(iNum1 as integer, iNum2 as integer): total = iNum1 * iNum2. message total view-as alert-box. end method. end class. Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

21 Definition: Override Override: Change the behavior of a super class method Overridden method must have same signature Can be used to define totally new behavior Or do pre-processing or post-processing To access super class method: SUPER:<method-name> Class SubCalculator implements iBaseCalculator: method override Add(iNum1 as integer, iNum2 as integer): /* new behavior */ end method. end class.

22 Definition: Polymorphism
Polymorphism: Ability to write generic code but call custom methods Code written using super class / interface (parent) type Tightly coupled to inheritance, interface and override behavior invoke an overridden method in a class Parent variable used at compile time Subclass created and assigned to parent variable at runtime Cool trick: Method called on parent object reference actually calls subclass method Method call on parent dispatched to subclass’ method at runtime

23 Invoke a Polymorphic Method
class BackwardCalculator implements iBaseCalculator: method void Subtract(iNum1 as integer, iNum2 as integer): total = iNum2 – iNum1 /* swap order */. end method. end class. =============================================================== define variable cal1 as iBaseCalculator. define variable cal2 as iBaseCalculator. cal1 = new Calculator(). cal1:Subtract(1-9). /* Calls Calculator:Subtract() */ cal2 = new BackwardCalculator(). cal2:Subtract(1-9). /* Calls BackwardCalculator:Subtract() */ Classes in the 4GL are strongly type. Each class is identified by its class type and class-type is used for strong typing. The class type has two portions, an optional class package name and a class name. The package name is a (.) dot separated list of components. In Progress every class is stored in a separate file. The name of this file must be the same as the name of the class, with the extension .cls added. For example the class ‘Order’ would be stored in Order.cls. This class file must be stored in a directory that has the same components as the package. For example, if the type name for this class was acme..request.Order, the full path of the class file must be acme\request\order.cls. This directory must be found on ProPath. Describe INHERITS. This class gets non-private data members and non-private methods of ALL super classes. Describe IMPLEMENTS. The compiler verifies this class implements ALL methods defined in the interface. Why Interfaces? To have a set of objects all support a common set of methods. An interface file contains a set of behavior (methods) that an application wants all classes that implement that interface to have. Therefore, anyone that uses one of these classes is guaranteed to support all the methods in the interface. FINAL class can not be inherited.

24 Benefits of Polymorphism
Supports generic programming using super class or interface Type used at compile time is super class or interface New subclasses can be defined and code doesn’t need to change Specialized behavior is called at runtime automatically

25 Definition: Abstract Class
Abstract class: part of class implementation is missing Combines an interface and a class in a single definition Used when some behavior must be specialized and some can be shared All implemented properties and methods are available to subclass A subclass needs to inherit from an abstract class Class cannot be directly instantiated

26 Package Package: Uniquely identify the Type from other Types
Type name = Package name and Class name Defines the directory where code lives foo.bar.MyClass is foo/bar/MyClass.cls Must identify Type using fully qualified Type name Or add USING statement for the class or package with wildcard /* Class file must be located in math/Calculator.r */ Class Math.Calculator: ... ============================================ define variable cal as Math.Calculator. cal = new Math.Calculator().

27 Questions Inheritance Interfaces Override Polymorphism Abstract class
Package

28 OOABL Specializations
Classes and Procedures Progress.Lang.Object Progress.Lang.Class Compiler changes

29 Classes and Procedures
Classes Procedures Class files (.cls) Data members Void methods Non-void methods Constructor Inheritance Procedure file (.p) Define variables Internal procedures User-defined functions Code in main block Super procedures As 4GL developers you are already familiar with many of the capabilities that are part of the Object Oriented features in the 4GL. We are introducing a CLASS file which is similar to a persistent procedure. There are differences and they will be highlighted throughout this presentation. A persistent procedure can have variables scoped to the entire procedure. In a similar way, class files can contain data members. Data members in a class files are nothing more that data variables defined in a procedure except they have a access modifier, which we will talk about shortly. Class files have methods, which are similar to internal procedures and user defined functions. Many developers but code in the main block of the persistent procedure, which gets executed when the procedure is instantiated. Similarly a class file has an explicitly constructor. Lastly, procedures have a super procedure chain and class files also have an inheritance chain.

30 Classes and Procedures: Interoperability
Can use an Object Create and delete an Object Invoke methods using object reference Pass objects as a parameter Classes Can RUN a procedure or persistent procedure Can RUN internal procedures and user-defined functions on a handle Note can not RUN a class nor NEW a persistent procedure.

31 Classes and Procedures: Behavior Differences
Procedures and Classes Modular programming Supports reuse of common behavior (super) Classes only Programming errors caught early by compiler Natural integration with modeling tools and other Object-oriented platforms like .NET™ Modern programming model (used at most universities)

32 Progress.Lang.Object Implicit super class for all user-defined classes. Facilitates generic code Methods ToString ( ) GetClass ( ) Equals ( ) – Must be overridden Clone ( ) – Must be overridden Properties Next-sibling Prev-sibling ProObject is a built-in class definition that is the ultimate super-class for all classes. The super-class at the top of any hierarchy implicitly inherits from ProObject. At the top of every class inheritance chain is the ProObject class. ProObject provides a common set of data members that are available for any instance of any class. These data members are similar to the built-in attributes for the Progress procedure object. Treating them as data member for a class makes them more consistent with the rest of the object-oriented definition of classes. Since every class derives from ProObject, you can define an object reference of type ProObject and set it equal to any object within the 4GL. As with any class reference, the use of a ProObject reference is limited to the methods defined for the ProObject class, although you can always cast the object reference as appropriate.

33 Progress.Lang.Class Used for reflection One per user-defined type
Methods IsInterface () IsFinal () Properties TypeName Package SuperClass ProClass is ‘reflection’ in Object-oriented terminology, i.e. how reflection is done. It provides type information – methods, signatures, parameters, etc. It is not in the class hierarchy. The ProClass class provides a common set of methods that give information regarding a class or interface. ProClass is FINAL and therefore it can not be inherited. The methods and attributes available on the ProClass are yet to be finalized. The ProObject is the root node of all classes – everything inherits from it. It contains commonly used methods as well as providing access to the ProClass.

34 Compiler changes Two pass compiler
First pass gathers Type information Second pass does validation and compilation Compile time validation of object reference Validates Methods Parameters Compiles all files in class hierarchy Does not compile subclasses Might need to compile Types referenced in code I have mentioned that we now verify object reference assignments, method invocation and verify the parameters at compile time. This is achievable because we now have a two-pass compiler. ProPath at compile needs to be correct. When you use the COMPILE statement to compile a .p, the compiler produces a .r file for the procedure file you identified (assuming the correct options are specified – SAVE). For a class hierarchy, the compiler will compile all class files in the hierarchy. Therefore you will have multiple .r files generated during the compilation of a class – one for each class file in the hierarchy. Class A, B and C are in a class hierarchy, where Class A is the super-class, and Class B and C are subclasses. Class B inherits from Class A; Class C inherits from Class B. Class Bar is a subclass of Class Foo. Class C makes a call to Class Bar. At compile time, when Class C is compiled, the compiler will follow the class hierarchy and compile Class B; and Class A. This could include re-compiling these classes. Because Class C references Class Bar, the compiler will check Class Bar for validity, including checking Class Foo. However, neither Class Bar or Class Foo will be compiled as a part of the compilation of Class C. In a future release, the recompilation of recently compile classes will be eliminated.

35 Questions Classes and Procedures Progress.Lang.Object
Progress.Lang.Class Compiler changes

36 Part 2: Even More Advanced Features
Static Class members Events Chaining method calls Garbage collection Class browser in PDSOE

37 In Summary Standard OO concepts available in the 4GL
Built on top of existing 4GL constructs Interoperability between Classes and Procedure "Be part of the cool crowd"  Procedure live! This is an alternative to your procedure development model.

38 Questions

39


Download ppt "OpenEdge® Object-oriented ABL"

Similar presentations


Ads by Google