45
Salvador Viñals Consultant Product Manager svi @ progress.com OpenEdge 10.1A1B Beta Object-oriented programming in the Progress® 4GL 10.1A Beta

Salvador Viñals Consultant Product Manager [email protected] OpenEdge 10.1A1B Beta Object-oriented programming in the Progress® 4GL 10.1A Beta

Embed Size (px)

Citation preview

Salvador ViñalsConsultant Product [email protected]

OpenEdge 10.1A1B Beta

Object-oriented programming in the Progress® 4GL 10.1A Beta

2 © 2005 Progress Software Corporation

Agenda

Introduction and goals of OO in the 4GL Concepts and overview An example Tools support for OO in the 4GL Beta use cases

3 © 2005 Progress Software Corporation

Object-oriented Application Development

A way to design and build applications– Objects bundle together data (state) and

methods (behavior)

– Objects facilitate separating definition from implementation

Much more than just syntax– You might have already done object-oriented

programming in the 4GL

4 © 2005 Progress Software Corporation

Object-orientation and the 4GL

Extend the 4GL to support the OO programming model– Retain existing strengths

A natural basis for OpenEdge Reference Architecture applications

Programming with classes More closely support SOA Multiple rollouts

– 10.1A first one

Goals

5 © 2005 Progress Software Corporation

OO in the 4GL Features

CLASS definitions Single inheritance hierarchies Data members and methods Interfaces

6 © 2005 Progress Software Corporation

Benefits of OO in the 4GL

Programming Business

Encapsulation Maintenance

Inheritance Promotes reuse

Code reuse Productivity

Interfaces Contracts

Strong typing Robustness

Invocation model Ease of use

Maps modeling tools Efficient dev cycle

.cls - .p interoperability Not disruptive

7 © 2005 Progress Software Corporation

Poll

Are you familiar with Object-oriented Programming concepts?– Type– Class– Data members and methods– Interface– Inheritance– Polymorphism– Objects

<Please “click” Yes or No, using the menu-bar>

8 © 2005 Progress Software Corporation

Poll

How many using SUPER-PROCEDURES?

<Please “click” Yes or No, using the menu-bar>

9 © 2005 Progress Software Corporation

Similarities betweenClasses and Procedures

Procedures Classes

Procedure files (.p) Class files (.cls)

Define variables Data members

Internal procedures VOID methods

User defined functions Other methods

Code in main block Constructor

Super-procedures Inheritance

10 © 2005 Progress Software Corporation

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

11 © 2005 Progress Software Corporation

Agenda

Introduction and goals of OO in the 4GL Concepts and overview An example Tools support for OO in the 4GL Beta use cases

12 © 2005 Progress Software Corporation

Object-Oriented ConceptsWhat do I need to understand before I learn OO4GL?

OO terminology for familiar concepts– Classes, types, data members, methods & objects

Encapsulation– Grouping data & behavior together

Inheritance– Re-using and extending code

Delegation– Letting contained objects do their own work

Polymorphism– Generic code for objects with common data & behavior

Interfaces– Implementing a standard set of methods

13 © 2005 Progress Software Corporation

Types

Each class represents a new data type– Variables, parameters, return types

Allows for strong-typing – Early binding - types determined at

compile time

– Type-consistency enforced at compile time and runtime

A Type is a definition

14 © 2005 Progress Software Corporation

Types – An Example

Types: Order

InternalOrder– Sub-Type of

Order

ExternalOrder– Sub-Type of

Order

Order

InternalOrder ExternalOrder

is a is a

A Sub-Type can appear anywhere a Super-Type is expected

15 © 2005 Progress Software Corporation

Benefits of Types

Compile time checking for type consistency

myObj = mySubObject. (must be Sub-Type)

myObj:method(…). (validates signature)

myObj:data = 3. (validates data type)

Results in safer, bug-free code because all code paths checked at compile time

Develop super-classes first

Strong Typing

16 © 2005 Progress Software Corporation

Class: OrderorderNum AS INTcustNum AS INT

CalculateTotalPrice( )

PUBLIC:CreateOrder( )UpdateOrder( )GetOrderTotal( )Next( )

Class

A Class defines and implements a user-defined type

A Class is a template (blueprint) for an object:– Data– Methods– Relationships to

other classes

M

eth

od

s

Dat

a

A Class implements a Type

17 © 2005 Progress Software Corporation

The CLASS Construct

CLASS [<package>.]<class-name> [INHERITS <super-type-name> ] [IMPLEMENTS <interface-type-name> [,<interface-type-name>]…] [ FINAL ]:

[ <data member> …][ <constructor> ][ <method> … ][ <destructor> ]

END [ CLASS ].

18 © 2005 Progress Software Corporation

The CLASS Construct

CLASS [<package>.]<class-name> [INHERITS <super-type-name> ] [IMPLEMENTS <interface-type-name> [,<interface-type-name>]…] [ FINAL ]:

[ <data member> …][ <constructor> ][ <method> … ][ <destructor> ]

END [ CLASS ].

CLASS Acme.Inventory.Order: …

• Use packages to group classes

• Package maps to physical file relative to PROPATH

at compile time AND run time

• Period “.” maps to slash “/”, “\” in directories

19 © 2005 Progress Software Corporation

The CLASS Construct

CLASS [<package>.]<class-name> [INHERITS <super-type-name> ] [IMPLEMENTS <interface-type-name> [,<interface-type-name>]…] [ FINAL ]:

[ <data member> …][ <constructor> ][ <method> … ][ <destructor> ]

END [ CLASS ].

• Use inheritance to abstract out common data and functionality

• Sub-classes inherit all data members & methods from their super-classes

• Sub-classes may extend or change behavior by overriding methods of super-class

20 © 2005 Progress Software Corporation

The CLASS Construct

CLASS [<package>.]< <class-name> [INHERITS <super-type-name> ] [IMPLEMENTS <interface-type-name> [,<interface-type-name>]…] [ FINAL ]:

[ <data member> …][ <constructor> ][ <method> … ][ <destructor> ]

END [ CLASS ].

Encapsulation through class members:

• Data• Methods

Access types: • PUBLIC• PRIVATE• PROTECTED

Classes are always PUBLIC

21 © 2005 Progress Software Corporation

The Class File

Filename consists of package and class name– One class per file

.cls extension Compiles to r-code

22 © 2005 Progress Software Corporation

Creating Class Instances

Example

The NEW statement (equivalent to RUN)

<obj-ref> = NEW <type-name> ([<parameter>[,…]]) [ NO-ERROR ].

DEFINE VARIABLE myOrder AS Acme.Inventory.Order NO-UNDO.

myOrder = NEW Acme.Inventory.Order ( ).

23 © 2005 Progress Software Corporation

Agenda

Introduction and goals of OO in the 4GL Concepts and overview An example Tools support for OO in the 4GL Beta use cases

24 © 2005 Progress Software Corporation

Object-orientation – An Example

Application needs to manage two sets of orders for the same items:– Customer orders

Need to check valid customer and credit-limit Charge Shipping and logistics

– Internal orders Need to check valid department and cost center No charge Internal delivery

– Inventory is common

25 © 2005 Progress Software Corporation

Access Levels

Private

Public

Protected

Accessible by super-class only

Accessible by super- class & sub-classes

Accessible by super-class, sub-classes & other classes

Class Order

DEF PRIVATE VAR OrderNum AS INT

DEF PRIVATE VAR CustNum AS INT

DEF PRIVATE VAR ShipDate AS DATE

DEF PRIVATE VAR OrderStatus AS CHAR

METHOD PROTECTED … calculatePrice()

METHOD PUBLIC VOID calculateTax()

METHOD PUBLIC VOID initOrder()

METHOD PUBLIC VOID updateOrder()

METHOD PUBLIC CHAR getCustomer()

METHOD PUBLIC CHAR getShipDate()

METHOD PUBLIC CHAR getStatus()

METHOD PUBLIC DEC getOrderTotal()

26 © 2005 Progress Software Corporation

Inherit

from

Inheritance HierarchyInternalOrder Class

INHERITS Order

DEF … CostCenter AS INT

DEF … Department AS INT

METHOD … getCostCenter()

METHOD … getDepartment()

ExternalOrder Class

INHERITS Order

DEF … CustNum AS INT

DEF … CreditLimit AS DEC

METHOD … verifyCredit()

METHOD … getCustNum()

Class Order

DEF … OrderNum AS INT

DEF … CustNum AS INT

DEF … ShipDate AS DATE

DEF … OrderStatus AS CHAR

METHOD … calculatePrice()

METHOD … calculateTax()

METHOD … initOrder()

METHOD … updateOrder()

METHOD … getCustomer()

METHOD … getShipDate()

METHOD … getStatus()

METHOD … getOrderTotal()

27 © 2005 Progress Software Corporation

These objects of class types derived from Order may each behave differently when sent the InitOrder() message:

Polymorphism

myInternalOrder

CostCenter = 9145

Department = 5

myExternalOrder1

CustNum = 10

CreditLimit = 50000

myExternalOrder2

CustNum = 11

CreditLimit = 300000

if isValid(getCostCenter() and

getDepartment())

then call super-class’ initOrder()

else call super-class’ rejectOrder()

InitOrder

If (isValid(getCustNum()) and

verifyCredit())

then call super-class’ initOrder()

else call super-class’ rejectOrder()

InitOrder

28 © 2005 Progress Software Corporation

Contains

Delegation

Class Navigator

GuiHandler myGui

QueryHandler myQuery

initNavigator()

First()

Last()

Next()

Prev()

Cancel()

OK()

Class GuiHandler

FirstButtonPressed()

LastButtonPressed()

NextButtonPressed()

PrevButtonPressed()

OkButtonPressed()

CancelButtonPressed()

Class QueryHandler

OpenQuery()

CloseQuery()

GetFirstRec()

GetLastRec()

GetNextRec()

GetPrevRec()

29 © 2005 Progress Software Corporation

Agenda

Introduction and goals of OO in the 4GL Concepts and overview An example Tools support for OO in the 4GL Beta use cases

30 © 2005 Progress Software Corporation

Tools Support For OO in the 4GL

OpenEdge Architect– Code editors– Tools for Business Logic

Business Entity Designer OpenEdge Studio (AppBuilder) 4GL Development System (Procedure Editor) Application Compiler Debugger

– Compile Debug requires stub

Not in this beta

31 © 2005 Progress Software Corporation

Rules For .cls Files

Must have .cls extension to compile– Added to file filters

File and package name in class file must match physical location

Must save file to run

All editing environments

CLASS payroll.taxcalc:…END CLASS.

32 © 2005 Progress Software Corporation

AppBuilder Support

No AppBuilder changes to support class files Opened as unstructured procedures in

Procedure Window AppBuilder Procedure Window

– Same support as Procedure Editor Procedure Window supports remote

development– Web-disp.p cannot instantiate class files

Procedure Window

33 © 2005 Progress Software Corporation

Procedure Editor Support

New “*.cls” filter in GUI– File open

– Save

– Save As Source file types

– All Source (*.p, *.w, *.i, *.cls)

– Classes (*.cls) TTY has no filters

File filters

34 © 2005 Progress Software Corporation

Syntax Checking

Checking syntax of named edit buffers– Create temp directory(s)

– Contains class file of correct name Checking syntax of unnamed edit buffers

– Saves to temp file of .cls extension

– In current working directory An inherited super-class must be in

PROPATH for sub-classes to syntax check

36 © 2005 Progress Software Corporation

Application Compiler

Includes ‘.cls’ extension May compile super-classes

“Remove Old .r Files”– Super-classes .r is not

removed when compiling sub-classes

“Only Compile if No .r File”

37 © 2005 Progress Software Corporation

Agenda

Introduction and goals of OO in the 4GL Concepts and overview An example Tools support for OO in the 4GL Beta use cases

38 © 2005 Progress Software Corporation

Current Beta Use Cases (1/4)

Use Case ID: 101A4GL500 Use Case Name: OO4GL new design/development Description Apply Object-Oriented design principles to new 4GL application Actors 4GL architect/designer/developer Assumptions Knowledge of OO concepts Steps 1. Identify a new (not yet designed/implemented) 4GL application or new

component of an existing 4GL application 2. Create an object-oriented design for 4GL application:

a. define architecture b. analyze components c. determine data model d. determine object model e. define class hierarchies

3. Use new 4GL programming constructs to create user-defined classes for the design

Expected results or end state

Verify that the 4GL constructs provided are sufficient to implement your OO design.

39 © 2005 Progress Software Corporation

Current Beta Use Cases (2/4)

Use Case ID: 101A4GL501 Use Case Name: OO4GL existing OO model Description Transform existing ‘OO’ 4GL app to use new OO4GL constructs Actors 4GL architect/designer/developer Assumptions Knowledge of OO concepts Steps 1. Identify an existing 4GL application (or component) that employs OO

concepts, implemented with existing 4GL constructs, such as SUPER Procedures.

2. Use new 4GL programming constructs to implement the existing ‘OO’ design

Expected results or end state

Verify that the new 4GL constructs are sufficient to provide the same functionality as the existing 4GL features.

40 © 2005 Progress Software Corporation

Current Beta Use Cases (3/4)Use Case ID: 101A4GL502 Use Case Name: OO4GL implementation through user-defined classes Description Exercise the new OO4GL constructs Actors 4GL architect/designer/developer Assumptions Knowledge of OO concepts Steps 1. Start with an OO-designed 4GL application based on the new 4GL

features (see Use Case “101A4GL500 and 101A4GL501”) 2. Write 4GL code using the new language constructs that implement:

a. inheritance b. overriding c. polymorphism d. public/private/protected methods e. public/private/protected data members

i. temptables ii. buffers

iii. queries iv. built-in datatypes

f. methods with VOID and non-VOID return values g. constructors and destructors

Expected results or end state

Verify that the new 4GL features work according to the specified behavior.

41 © 2005 Progress Software Corporation

Current Beta Use Cases (4/4)

Use Case ID: 101A4GL503 Use Case Name: OO4GL use of User Defined Classes Description Use new OO4GL User-defined Classes as data types Actors 4GL architect/designer/developer Assumptions Knowledge of OO concepts Steps 1. Implement a new 4GL application (or component) using the new 4GL

constructs (see Use Case “101A4GL502”) 2. Instantiate your user-defined classes, and use them as you would built-

in datatypes: a. Pass as parameters b. Pass as return values c. Use as temptable fields d. Delete them

Expected results or end state

Verify that the user-defined classes’ methods and data members are accessible and behave as expected throughout these steps.

42 © 2005 Progress Software Corporation

In addition, you shall …

Validate interoperability

Gather information about increase in development / maintenance productivity

"Benchmark" runtime performance through testing of your user-defined classes

Share your findings– Multiple ways to design, organize any given

functionality

43 © 2005 Progress Software Corporation

In Summary

Standard OO concepts available in the 4GL

Built on top of existing 4GL constructs

Interoperability with Procedure / Functions– Can be combined with procedural

programming, not all or nothing

Many benefits in OO Programming

Major difference of OO: Enforcement

44 © 2005 Progress Software Corporation

Questions?

45 © 2005 Progress Software Corporation

Thank you for your time!

46 © 2005 Progress Software Corporation