2f4c3f126b4f4dc0c56c3e9972234f34.ppt
- Количество слайдов: 44
Object-oriented programming with Open. Edge® 10. 1 A PSDN Web Seminar February 2006 Salvador Viñals Consultant Product Manager Progress Software – Open. Edge Division
Audience § Technical level: Intermediate § This session is targeted to customers somewhat § 2 familiar with object-orientation This session does not focus on reference information © 2006 Progress Software Corporation
Open. Edge 10. 1 A Focus Improve the productivity of Open. Edge … to provide our partners significant competitive advantage through the software they develop and deploy 3 © 2006 Progress Software Corporation
Open. Edge 10. 1 A Highlights 4 What we are not going to talk about today… § Open. Edge Architect § Auditing § Language: short-hand syntax (: : ), READ-XML(), WRITEXML(), BY-REFERENCE, XP manifests, 64 bit r-code § RDBMS: performance, more online utilities and schema changes § JDBC Type 4 § Symbiotic Adapter for Sonic. MQ® § Install: Simpler, faster and embeddable § Rebranding: Fathom to Open. Edge § Replication: Enable online, AI, single command failback § DVD § Linux 64 bit (RH AS 3, Su. Se 9) …. and much more © 2006 Progress Software Corporation
Agenda § Object-orientation in Open. Edge 10. 1 A • Benefits • Positioning • Concepts and Features § Object-oriented programming § Where to go next 5 © 2006 Progress Software Corporation
Introducing OO in 10. 1 A Open. Edge® 10. 1 introduces formal objectoriented programming through language extensions that support user-defined classes. User-defined classes allow you to define objects, with methods and data, and interfaces for building business applications. 6 © 2006 Progress Software Corporation
Object-orientation Benefits § § § § 7 Let’s you organize applications the way you think: • around objects Increase application robustness (strong typing) More development productivity with encapsulation, inheritance, and polymorphism Promotes reusability Helps you build OERA. More closely support SOA • Modular. Components. Composite applications. • Service contracts = Interfaces Ease application maintenance Natural integration with: • modeling tools • other OO platforms Ease hire new developers © 2006 Progress Software Corporation
Positioning § § 8 When shall you consider using Classes? • For well defined and designed functional units • Not too coarse. Not too granular. • Useful (and easy) when called from at least three different modules of the application, or different applications • Need to adhere to Interfaces When Procedures are best? • Tasks • Processes • Workflows • Dynamic or late bound code (not strong typed) • Disposable programs © 2006 Progress Software Corporation
Quick facts § Multiple rollout strategy: Open. Edge 10. 1 A is the § § 9 first one The object-oriented extensions do not replace existing language constructs You do not need to use OO if you do not want Classes can include ON <event> constructs 10. 1 A language compiler is two-pass © 2006 Progress Software Corporation
Interoperability Procedures 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 10 © 2006 Progress Software Corporation
Similarities between Classes and 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 . p 11 . cls © 2006 Progress Software Corporation
Object-Oriented Concepts Overview What do you need to understand to use OO? § § § 12 OO terminology for familiar concepts • Classes, data members, methods, types & objects Encapsulation • Grouping data & behavior together Inheritance • Re-using and extending code Delegation • Letting contained objects do their own work Interfaces • Implementing a standard set of methods Polymorphism • Generic code for objects with common data & behavior © 2006 Progress Software Corporation
OO in the 10. 1 A Features § § § § § 13 CLASS definitions Single inheritance hierarchies Data members and methods Interfaces Polymorphism Delegation CAST function VALID-OBJECT() method. cls files Support with development tools © 2006 Progress Software Corporation
Details on Object-Oriented Concepts Overview and 10. 1 A Features § Refer to the following 10. 1 A Beta program presentations that will be made available on PSDN along with this Web seminar: • (beta) Object-oriented programming in the Progress 4 GL 10 1 A 1 B Webinar. ppt • (beta) Object-oriented programming in the Progress 4 GL 10 1 A 2 B Webinar. ppt 14 © 2006 Progress Software Corporation
Agenda § Object-orientation in Open. Edge 10. 1 A • Benefits • Positioning • Concepts and Features § Object-oriented programming § Where to go next 15 © 2006 Progress Software Corporation
Object-oriented programming § When shall you consider using Classes? • For well defined and designed functional units • Not too coarse. Not too granular. • Useful (and easy) when called from at least three different modules of the application, or different applications • Need to adhere to Interfaces § How to start? • You need a model (white-board models are good) • Best not to start with the presentation layer • Best not to start with the data management layer • Start inside-out: – Model the required functionality – Identify potential functional units candidates for classes 16 © 2006 Progress Software Corporation
Object-oriented programming § Logical model - Abstraction • Identify Classes. Data members. Methods. • Identify inheritance “chains” • Identify interfaces you need to conform to • Identify where you’ll need delegation, polymorphism, etc. • Refine: Too coarse? Too fine grained? Will you use it? § § 17 Implementation model • Define each of above • Refine as needed Start programming © 2006 Progress Software Corporation
Object-oriented programming § Logical model - Abstraction • Identify Classes. Data members. Methods. • Identify inheritance “chains” • Identify interfaces you need to conform to • Identify where you’ll need delegation, polymorphism, etc. • Refine: Too coarse? Too fine grained? Reusable? § § 18 Implementation model • Define each of above • Refine as needed Start programming © 2006 Progress Software Corporation
Business Abstraction Order § § § 19 What is an Order? Business Operations • Approve • Ship • Check Inventory Data Operations • Create • Read • Update • Delete © 2006 Progress Software Corporation
Higher Level Abstraction Business Entity § § What is a Business Entity • Tracks my business What do I do with a business entity • Business Operation – Security – Auditing • Delegate CRUD to Data Access in subclasses – – 20 Create Read Update Delete © 2006 Progress Software Corporation
Example of Logical Model Presentation Layer Integration 21 Data Access Business Processing © 2006 Progress Software Corporation
Example of More Detailed Logical Model Data Members Super Class Protected Methods Interface Inheritance Private Subclass Public Polymorphism Delegation Polymorphism 22 © 2006 Progress Software Corporation
Object-oriented programming § Logical model - Abstraction • Identify Classes. Data members. Methods. • Identify inheritance “chains” • Identify interfaces you need to conform to • Identify where you’ll need delegation, polymorphism, etc. • Refine: Too coarse? Too fine grained? Reusable? § § 23 Implementation model • Define each of above • Refine as needed Start programming © 2006 Progress Software Corporation
Super Class – Business Entity OOABL. Business. Entity # da. Object: IData. Access # lc. BEXMLData. Set: LONGCHAR + fetch. Where(): VOID + save. Changes(): VOID Type – <package>. <class> Data Members Methods What does a Business Entity need to do for the application? § Data Members • da. Object - Retrieve records • lc. BEXMLData. Set – Stores records in XML to pass around § Methods • fetch. Where –Select Records (Read) • save. Changes –Saves Changes (Create, Update, Delete) • Note: Example doesn’t contain Security or Auditing but that could be defined here as well 24 © 2006 Progress Software Corporation
Super Class – Business Entity CLASS OOABL. Business. Entity: /* data members */ DEFINE PUBLIC VARIABLE lc. BEXMLData. Set AS LONGCHAR NO-UNDO. /* methods */ METHOD PUBLIC LONGCHAR fetch. Where (INPUT c. BEWhere AS CHAR): END. /* fetch. Where*/ METHOD PUBLIC VOID save. Changes (): END. /* save. Changes */ END CLASS. /*Business. Entity Class*/ 25 © 2006 Progress Software Corporation
Inheritance Hierarchy Overview Re-using and extending code § Inheritance is used to abstract out common § § 26 functionality & data amongst similar classes Inheritance relationship means a sub-class inherits all data members & methods from a super class Resulting sub-class may extend or change behavior by overriding methods of super class or add functionality by adding new methods to the sub-class © 2006 Progress Software Corporation
Inheritance - An Example OOABL. Business. Entity # da. Object: IData. Access super class # lc. BEXMLData. Set: LONGCHAR + fetch. Where(): VOID + save. Changes(): VOID Inherits OOABL. BEOrder # ds. Order: dataset subclass + BEOrder (): VOID Additional + fetch. Where(): VOID Override + save. Changes(): VOID + process. Order(): VOID 27 Additional © 2006 Progress Software Corporation
Inheritance - An Example CLASS OOABL. BEOrder INHERITS OOABL. Business. Entity: {Pro. Data. Set/Private. Order. TT. i} {Pro. Data. Set/Private. DSOrder. i} CONSTRUCTOR PUBLIC BEOrder (OUTPUT l. Success AS LOGICAL): END CONSTRUCTOR. /* constructor BEOrder */ DESTRUCTOR PUBLIC BEOrder (): END DESTRUCTOR. /* destructor BEOrder */ METHOD PUBLIC OVERRIDE LONGCHAR fetch. Where (INPUT c. BEWhere AS CHAR): END. /* fetch. Where*/ METHOD PUBLIC OVERRIDE VOID save. Changes(): END. /* save. Changes */ METHOD PUBLIC VOID process. Order(): END. /* process. Order */ END CLASS. /*BEOrder Class*/ 28 © 2006 Progress Software Corporation
Delegation Overview Letting contained classes do their own work § Delegation may be used when an object is built from other objects that are not in the class hierarchy § The containing object forwards messages it can’t handle to a contained object, called its delegate § The containing object defines a “stub” for the message 29 © 2006 Progress Software Corporation
Delegation – An Example Business entity object delegates the record retrieval to data access object OOABL. DAOrder - ds. Order: handle + convert. To. DS(): VOID + convert. To. XML(): VOID + setc. Where(): VOID OOABL. BEOrder + getc. Where(): CHAR # ds. Order: dataset + BEOrder (): VOID + fetch. Where(): VOID delegates + set. Data. Sources(): VOID + select. Records(): LONGCHAR + save. Changes(): VOID + update. Records(): VOID + process. Order(): VOID + set. Callbacks(): VOID + post. Oline. Fill(): VOID + post. Data. Set. Fill(): VOID 30 © 2006 Progress Software Corporation
Delegation - Using an Interface to Ensure an API Animation walks through the code design… Order. Main. p /* Defines a BEOrder variable */ /* NEWs BEOrder */ /* calls BEOrder fetch. Where */ OOABL. Data. Object OOABL. Business. Entity # xml. Data. Set # da. Object: OOABLIData. Access # Data. Object() CONSTRUCTOR #lc. BEXMLData. Set: LONGCHAR /* methods from interface */ + fetch. Where(): VOID + select. Records(): VOID implements /* Passes dataset back to UI */ <interface> OOABL. IData. Access + select. Records(): VOID # ds. Order: dataset BEOrder() CONSTRUCTOR BEOrder() DESTRUCTOR + fetch. Where(): VOID Container Class 31 delegates OOABL. BEOrder inherits OOABL. DAOrder - ds. Order: handle + select. Records(): VOID Delegate Class © 2006 Progress Software Corporation
Delegation – An Example (complete sample code in annotations) CLASS OOABL. DAOrder INHERITS OOABL. Data. Object: {Pro. Data. Set/Private. Order. TT. i} {Pro. Data. Set/Private. DSOrder. i} CONSTRUCTOR PUBLIC DAOrder (): END CONSTRUCTOR. /** INHERITED METHODS OVERRIDE SECTION **/ METHOD PUBLIC OVERRIDE VOID Convert. To. DS (): /* Uses default READ-XML behavior */ DATASET ds. Order: READ-XML ("LONGCHAR", lc. XMLDATASET, "EMPTY", ? , ? ). END. /*END Convert. To. DS */ METHOD PUBLIC OVERRIDE VOID Convert. To. XML(): /* Default XML-WRITE to LONGCHAR */ DATASET ds. Order: WRITE-XML ("LONGCHAR", /* target-type */ lc. XMLDATASET, /* longchar */ TRUE, /* formatted */ ? , /* encoding */ ? , /* schema location */ ? , /* write schema */ ? ). /* minschema */ END. /* end of Convert. To. XML */ 32 . . . /. . . © 2006 Progress Software Corporation
Delegation – An Example (complete sample code in annotations) METHOD PUBLIC DEFINE OVERRIDE VARIABLE LONGCHAR hds. Order h. Events i. Buff h. Buff . . . /. . . select. Records (): AS HANDLE NO-UNDO. AS INTEGER NO-UNDO. AS HANDLE NO-UNDO. DEFINE QUERY q. Order FOR Sports 2000. Order, Sports 2000. Customer, Sports 2000. Sales. Rep. DEFINE DATA-SOURCE src. Order FOR QUERY q. Order KEYS (Order. Num), Customer KEYS (Cust. Num), Sales. Rep KEYS (Sales. Rep). DEFINE DATA-SOURCE src. Oline FOR Order. Line. hds. Order = DATASET ds. Order: HANDLE. /* Use NEW SET-CALLBACK Method for THIS-OBJECT instead of persistent proc */ Set. Call. Backs(INPUT hds. Order). /* Prepare the query */ QUERY q. Order: QUERY-PREPARE("FOR EACH Order WHERE ordernum = " + (c. Where) + ", FIRST Customer OF Order, FIRST Sales. Rep OUTER-JOIN OF Order"). /* Attach datasources before fill */ BUFFER tt. Order: ATTACH-DATA-SOURCE(DATA-SOURCE src. Order: HANDLE, "Customer. Name, Cust. Name"). BUFFER tt. Oline: ATTACH-DATA-SOURCE(DATA-SOURCE src. Oline: HANDLE). h. DSOrder: FILL(). /*Detach datasources after fill */ DO i. Buff = 1 TO DATASET ds. Order: NUM-BUFFERS: DATASET ds. Order: GET-BUFFER-HANDLE(i. Buff): DETACH-DATA-SOURCE(). END. convert. To. XML(). RETURN lc. XMLData. Set. END. /* select. Records */ 33 . . . /. . . © 2006 Progress Software Corporation
Interfaces Overview Implementing a standard set of methods § An interface specifies a set of method prototypes which must be implemented by a class in order to claim support for the interface • Reliably defines a common API supported by different classes • Use an INTERFACE to ensure the API exists § § 34 Similar to inheritance, except no default data to inherit & no default implementation for the methods A class may implement zero or more interfaces © 2006 Progress Software Corporation
Interface – An Example OOABL. data. Object # xml. Data. Set: LONGCHAR # h. Data. Set: HANDLE <interface> # c. Where: CHARACTER OOABL. IData. Access # Data. Object() + convert. To. DS(): VOID + setc. Where(): VOID implements + convert. To. XML(): VOID + getc. Where(): CHAR + setc. Where(): VOID + set. Data. Source(): VOID + getc. Where(): CHAR + select. Records(): LONGCHAR + set. Data. Source(): VOID + update. Records(): VOID + select. Records(): LONGCHAR + update. Records(): VOID 35 © 2006 Progress Software Corporation
Interface – An Example (all data. Object classes will implement this interface) INTERFACE OOABL. IData. Access: METHOD PUBLIC VOID setc. Where(INPUT ic. Where AS CHARACTER). /* will set the where clause for record selection */ METHOD PUBLIC CHAR getc. Where (). /* will get the where clause for record selection */ METHOD PUBLIC VOID set. Data. Sources(INPUT c. Data. Sources AS CHARACTER). /*will initialize the dataset's datasources */ METHOD PUBLIC LONGCHAR select. Records(). /* will select object specific records */ METHOD PUBLIC VOID update. Records(INPUT lc. XML AS LONGCHAR). /* store create, updates, and deletes to records */ METHOD PUBLIC VOID convert. To. DS (). METHOD PUBLIC VOID convert. To. XML (). END INTERFACE. /*IData. Access */ 36 © 2006 Progress Software Corporation
Polymorphism Overview Treating similar objects generically § § Multiple classes can inherit from same super class Each can override behavior in super class • Multiple implementations • Different behavior § § Instances of classes derived from the same super class can be dealt with generically at runtime A message in the super class is dispatched to the corresponding method in a subclass • Polymorphism means each subclass may respond to the same message in a different manner 37 © 2006 Progress Software Corporation
Polymorphism – An Example OOABL. BEOrder # ds. Order: dataset + BEOrder (): VOID + fetch. Where(): VOID + save. Changes(): VOID + process. Order(): VOID OOABL. BEExternal. Order OOABL. BEInternal. Order - Invoice. Num: INTEGER -cross. Charge. Dept. Num: INTEGER + process. Order(): VOID - send. Invoice. Info(): VOID - get. Cross. Charge. Dept(): CHAR - start. Session(): VOID - set. Cross. Charge. Dept(): VOID - cross. Charge(): VOID 38 © 2006 Progress Software Corporation
Polymorphism – An Example (complete sample code in annotations) CLASS OOABL. BEOrder INHERITS OOABL. Business. Entity: . . . CLASS OOABL. BEExternal. Order INHERITS OOABL. BEOrder FINAL: . . . CLASS OOABL. BEInternal. Order INHERITS OOABL. BEOrder FINAL: . . . /* Process. Order. Main. p -- Main procedure for an Order Dataset */ DEFINE DEFINE INPUT PARAMETER l. Internal AS LOGICAL NO-UNDO. INPUT PARAMETER pi. Order. Num AS INTEGER NO-UNDO. OUTPUT PARAMETER l. Processed AS LOGICAL NO-UNDO. VARIABLE my. BEOrder AS CLASS OOABL. BEOrder NO-UNDO. VARIABLE lc. XML AS LONGCHAR NO-UNDO. VARIABLE l. Success AS LOGICAL NO-UNDO. /* Instantiate the right subclass */ IF l. Internal THEN my. BEOrder = NEW OOABL. BEInternal. Order(OUTPUT LSuccess). ELSE my. BEOrder = NEW OOABL. BEExternal. Order(OUTPUT l. Success). /* fetch the right order and orderlines */ lc. XML = my. BEOrder: fetch. Where(STRING(pi. Order. Num)). my. BEOrder: process. Order(OUTPUT l. Processed). DELETE OBJECT my. BEOrder. 39 © 2006 Progress Software Corporation
Polymorphism – Another Example Director. p /* Defines a Boss variable */ /* NEWs Boss (Regional. Manager or Corporate. Manager */ /* sets Boss’ c. Task. To. Delegate */ /* calls Boss’ delegate. Task */ /* deletes Boss object etc. */ OOABL. Worker + Boss() CONSTRUCTOR + Boss() DESTRUCTOR + delegate. Task(): LOGICAL + Announce. Results(): VOID <interface> - c. Task: CHARACTER /* methods from interface */ + setc. Task(): VOID + getc. Task(): CHARACTER + complete. Task: LOGICAL OOABL. IJob. Task implements # My. Worker. Object: Worker delegates OOABL. Boss + setc. Task(): VOID + getc. Task(): CHARACTER + complete. Task: LOGICAL polymorphism OOABL. Regional. Manager + Announce. Results(): VOID 40 OOABL. Corporate. Manager + Announce. Results(): VOID © 2006 Progress Software Corporation
Where to go next … Product Documentation § Open. Edge Getting Started: Object-oriented Programming Education Course § What's New in Open. Edge 10. 1: Object Oriented Programming (April 2006) PSDN § § 41 Article: Object-orientation and the Progress® ABL in Open. Edge® Release 10. 1 A Development patterns web papers (coming up soon) © 2006 Progress Software Corporation
Thank you for your time! 42 © 2006 Progress Software Corporation
Questions 43 © 2006 Progress Software Corporation
44 © 2006 Progress Software Corporation
2f4c3f126b4f4dc0c56c3e9972234f34.ppt