Presentation is loading. Please wait.

Presentation is loading. Please wait.

ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha Kraljevic Principal TSE.

Similar presentations


Presentation on theme: "ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha Kraljevic Principal TSE."— Presentation transcript:

1 ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha Kraljevic Principal TSE

2 © 2007 Progress Software Corporation 2 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in the OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

3 © 2007 Progress Software Corporation 3 ARCH-11: Building your Presentation with Classes  Provides a high-level blueprint  Allows you to separate concerns  Helps you not to complicate your life  Facilitates agile design and development Presentation Layer in OERA OpenEdge ® Reference Architecture

4 © 2007 Progress Software Corporation 4 ARCH-11: Building your Presentation with Classes OpenEdge Reference Architecture Presentation Business Components Data Access Data Sources Common Infrastructure Enterprise Services

5 © 2007 Progress Software Corporation 5 ARCH-11: Building your Presentation with Classes OpenEdge Reference Architecture Presentation Business Components Data Access Data Sources Common Infrastructure Enterprise Services Presentation controls the user interface and requests data and other services

6 © 2007 Progress Software Corporation 6 ARCH-11: Building your Presentation with Classes Demo – What do we want to achieve?

7 © 2007 Progress Software Corporation 7 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

8 © 2007 Progress Software Corporation 8 ARCH-11: Building your Presentation with Classes 1. Have a clearly defined interface to Business Components (BC) and Common Infrastructure (CI) 2. Be able to serve different UI client types 3. Allow reuse of common code shared by different UI client types 4. Lend itself to testing Presentation Layer - Requirements …must:

9 © 2007 Progress Software Corporation 9 ARCH-11: Building your Presentation with Classes  Able to locate required services in the BC & CI layers  Able to communicate with them  Able to handle dependencies on application state in a loosely coupled way Requirement 1: The Presentation has a clearly defined interface to BC & CI layers Components in the Presentation layer should be:

10 © 2007 Progress Software Corporation 10 ARCH-11: Building your Presentation with Classes  Should not be a single monolithic body of code  Should handle user actions in the same way regardless of the UI type  Should take into account the UI type and session state, for example: HTTP/*ML is ‘stateless’ Client/Server GUI may maintain state Requirement 2: The Presentation can serve different UI client types The Presentation layer:

11 © 2007 Progress Software Corporation 11 ARCH-11: Building your Presentation with Classes  Some code is responsible for handling information This should be UI independent  Some code is responsible for responding to user actions This will be UI type dependent  Some code is responsible for rendering the user interface This will be UI type dependent Requirement 3: The Presentation allows reuse of common code In the Presentation layer :

12 © 2007 Progress Software Corporation 12 ARCH-11: Building your Presentation with Classes  User interfaces are complicated to test User actions can be hard to capture Small changes to the UI disrupt saved tests  The Presentation architecture should facilitate automated testing Requirement 4: The Presentation lends itself to testing

13 © 2007 Progress Software Corporation 13 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

14 © 2007 Progress Software Corporation 14 ARCH-11: Building your Presentation with Classes  A number of existing patterns can be used  Choose one or more that match best to the requirements  To list some: - MVC (Model View Controller) - MVP (Model View Presenter) and their derivatives… Design Patterns

15 © 2007 Progress Software Corporation 15 ARCH-11: Building your Presentation with Classes Model-View-Controller versus Model-View-Presenter Controller Model View Presenter Model View MVC – Model View Controller MVP – Model View Presenter

16 © 2007 Progress Software Corporation 16 ARCH-11: Building your Presentation with Classes Presenter versus Passive View Presenter Model View MVP – Model View Presenter Presenter Model View MVP – Passive View

17 © 2007 Progress Software Corporation 17 ARCH-11: Building your Presentation with Classes Design Patterns – Composite pattern for Views

18 © 2007 Progress Software Corporation 18 ARCH-11: Building your Presentation with Classes Design Patterns – Composite pattern for Presenters

19 © 2007 Progress Software Corporation 19 ARCH-11: Building your Presentation with Classes Example View

20 © 2007 Progress Software Corporation 20 ARCH-11: Building your Presentation with Classes The View with the Presenter and Model VIEW PRESENTER MODEL

21 © 2007 Progress Software Corporation 21 ARCH-11: Building your Presentation with Classes Design Patterns – Back to the OERA

22 © 2007 Progress Software Corporation 22 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

23 © 2007 Progress Software Corporation 23 ARCH-11: Building your Presentation with Classes The Service Adapter and Service Interface Presentation Business Components Data Access Data Sources Common Infrastructure Enterprise Services Client session AppServer session Service Adapter Service Interface  Service Adapter sits outside the Model Connects the Presentation to Service Interface  Service Interface sits “above” the Business Components Routes each request to the right Business Component

24 © 2007 Progress Software Corporation 24 ARCH-11: Building your Presentation with Classes Support for a Business Component Type The Model The role of the Model in the Architecture Service Adapter Client Business Component Data Instance Client Business Component Data Instance Service Adapter Client Business Component Data Instance Client Business Component Data Instance Service Interface Business Component

25 © 2007 Progress Software Corporation 25 ARCH-11: Building your Presentation with Classes Implementing the Model with classes  The Model holds data on behalf of the View  There is a Client Business Component (CBC) type for each Business Component type Presentation layer Customer CBC type maps to a Customer Business Entity  There is one instance of a CBC for each View element that requests distinct data of the type

26 © 2007 Progress Software Corporation 26 ARCH-11: Building your Presentation with Classes Data instances  Data is not held persistently in the Business Components on the server  A Data Instance can represent a simple object (a row), a complex object (a DataSet or other form), a set of rows  A Data Instance can be held by a Client Business Component and bound to by the View  A Data Instance in the Model can be held as long as the data is needed  A Data Instance can be shared by multiple Views

27 © 2007 Progress Software Corporation 27 ARCH-11: Building your Presentation with Classes Presentation Business Component Data Access Data Sources Enterprise Services CBC SalesRep View1 SalesReps View2 Common Infrastructure Example: a data instance for SalesReps Presenter All SalesReps Svc Adapter SalesRep SalesRep BE All SalesReps SalesRep DAO BIND

28 © 2007 Progress Software Corporation 28 ARCH-11: Building your Presentation with Classes Data Instances on server and client  On the server: A single Business Component can be refreshed and reused for all requests The same Business Components can be used to supply data to Enterprise Services  On the client: A single Service Adapter can be used for all instances of a type in a session Distinct Views can have distinct CBC instances A single CBC instance can be reused to supply different data to a given View

29 © 2007 Progress Software Corporation 29 ARCH-11: Building your Presentation with Classes Order BE Presentation Business Component Data Access Data Sources Enterprise Services Order Order OrderLine Common Infrastructure CBC Order View1 Order View2 Order Presenter Order 1 Svc Adapter Orders Order 1 CBC Order 3 Order 5 Example: Sharing and reusing data instances Order DAO

30 © 2007 Progress Software Corporation 30 ARCH-11: Building your Presentation with Classes Service Adapters Common Infrastructure The Model Client-side code hierarchies componentbase.cls clientcomponent.cls beCustomer.cls serviceadapter.cls saCustomer.cls servicemanager.cls manager.cls factory.p INHERITS INVOKES

31 © 2007 Progress Software Corporation 31 ARCH-11: Building your Presentation with Classes Looking at class-based ABL code: clientcomponent super class  CLASS inherits behavior from a base class  PUBLIC property protects setting the value  PROTECTED VARIABLE protects access to the value Also defined as a specific class type CLASS pres.clientcomponent INHERITS base.componentbase: /* Handle for the default query on the top-level DataSet buffer */ DEFINE PUBLIC PROPERTY hTopRelQuery AS HANDLE NO-UNDO GET. PROTECTED SET. DEFINE PROTECTED VARIABLE AdapterRef AS pres.serviceadapter NO-UNDO. END CLASS.

32 © 2007 Progress Software Corporation 32 ARCH-11: Building your Presentation with Classes Client Business Component subclass  CLASS inherits behavior from the super class  CONSTRUCTOR executed on creation  PROTECTED variable can be set from this subclass  PROPERTY hTopRelQuery accessed just like a variable CLASS samples.pres.beCustomer INHERITS pres.clientcomponent: {samples/dsCustomer.i} CONSTRUCTOR beCustomer(): AdapterRef = CAST (servicemgr:startService ("samples.pres.saCustomer“, "sa"), samples.pres.saCustomer). CREATE QUERY hTopRelQuery. hTopRelQuery:ADD-BUFFER(DATASET dsCustomer:GET-BUFFER-HANDLE(1)). hTopRelQuery:QUERY-PREPARE ("FOR EACH " + DATASET dsCustomer:GET-BUFFER-HANDLE(1):NAME). END CONSTRUCTOR. DEFINE PROTECTED VARIABLE AdapterRef AS pres.serviceadapter NO-UNDO.

33 © 2007 Progress Software Corporation 33 ARCH-11: Building your Presentation with Classes Methods in the Client Business Component  Method is PUBLIC to allow access from Presenter VOID return type  fetchData reference in AdapterRef verified by compiler METHOD PUBLIC VOID fetchWhere (INPUT-OUTPUT DATASET-HANDLE phDSContext): DEFINE VARIABLE iBuffer AS INTEGER NO-UNDO. DEFINE VARIABLE hDataSet AS HANDLE NO-UNDO. AdapterRef:fetchData(OUTPUT DATASET dsCustomer, INPUT-OUTPUT DATASET-HANDLE phDSContext). hDataSet = DATASET dsCustomer:HANDLE. DO iBuffer = 1 TO hDataSet:NUM-BUFFERS: hDataSet:GET-BUFFER-HANDLE(iBuffer): TABLE-HANDLE:TRACKING-CHANGES = YES. END. END METHOD. DEFINE PROTECTED VARIABLE AdapterRef AS pres.serviceadapter NO-UNDO.

34 © 2007 Progress Software Corporation 34 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

35 © 2007 Progress Software Corporation 35 ARCH-11: Building your Presentation with Classes CLASS presCustomerMaintenance INHERITS base.presenter: &Scoped-define REFERENCE-ONLY REFERENCE-ONLY {samples/dsCustomer.i {&REFERENCE-ONLY}} /* DEFINE DATASET dsCustomer REFERENCE-ONLY FOR eeCustomer. */ DEFINE VARIABLE clsCbcCustomer AS samples.cbcCustomerMaintenance NO- UNDO GET. PRIVATE SET. DEFINE PRIVATE VARIABLE hViewer AS HANDLE NO-UNDO. … END CLASS. Looking at class-based ABL code: presenter class  CLASS inherits behavior from a base presenter class  PRIVATE setter protects setting the value  PRIVATE VARIABLE protects access to the value Also defined as a specific class type where the view is realized using class type

36 © 2007 Progress Software Corporation 36 ARCH-11: Building your Presentation with Classes CLASS presCustomerMaintenance INHERITS base.presenter: … CONSTRUCTOR PUBLIC presCustomerMaintenance ( ): SUPER (). clsCbcCustomer = NEW samples.cbcCustomerMaintenance(). IF SESSION:CLIENT-TYPE = "4GLCLIENT" OR SESSION:CLIENT-TYPE = "WEBCLIENT" THEN DO: RUN CustomerMaintenance.w PERSISTENT SET hViewer. RUN setPresenter IN hViewer (INPUT THIS-OBJECT ) NO-ERROR. RUN populateData IN hViewer NO-ERROR. RUN enable_UI IN hViewer NO-ERROR. WAIT-FOR CLOSE OF hViewer. END. Looking at class-based ABL code: presenter constructor  SUPER() calls constructor in a base presenter class  Instantiate the Client Business Component  RUN the view, pass the reference to the presenter object, populate data and enable the UI The View can be realized as the specific class type instead of the ABL persistent procedure

37 © 2007 Progress Software Corporation 37 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

38 © 2007 Progress Software Corporation 38 ARCH-11: Building your Presentation with Classes The View: /* ***********Included Temp-Table & Buffer definitions ******** */ {samples/eCustomer.i} /*Temp-table defined as REFERENCE-ONLY */ /* Local Variable Definitions ---*/ DEFINE DATASET dsCustomer REFERENCE-ONLY FOR eeCustomer. DEFINE VARIABLE clsPresenter AS presCustomerMaintenance NO-UNDO.... ON CHOOSE OF BtnDone IN FRAME DEFAULT-FRAME /* Done */ DO: clsPresenter:exitObject(). END. PROCEDURE populateData : clsPresenter:fetchData(OUTPUT TABLE eeCustomer BY-REFERENCE ). END PROCEDURE. PROCEDURE setPresenter : DEFINE INPUT PARAMETER clsObj AS presCustomerMaintenance. clsPresenter = clsObj. END PROCEDURE.

39 © 2007 Progress Software Corporation 39 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

40 © 2007 Progress Software Corporation 40 ARCH-11: Building your Presentation with Classes Integration with Common Infrastructure Presenter class & procedures – Service Adapter to CI CLASS service.ServiceMgr INHERITS Base IMPLEMENTS IComponentFactory,IComponentRegistry USE-WIDGET- POOL : … END CLASS. Remember inheritance?  presCustomerMaintenance inherits base.presenter  Base.presenter inherits ‘base’ class  ‘base’ class defines class variable ‘clsServiceMgr’ Using Service Manager class methods, we now have access to all other services in CI !!!

41 © 2007 Progress Software Corporation 41 ARCH-11: Building your Presentation with Classes Agenda  Presentation Layer in OERA  Requirements  Design Patterns  Implementing the Model  Implementing the Presentation  Implementing the View  Integration with Common Infrastructure  Summary

42 © 2007 Progress Software Corporation 42 ARCH-11: Building your Presentation with Classes Demo – What have we achieved?

43 © 2007 Progress Software Corporation 43 ARCH-11: Building your Presentation with Classes In Summary  Separate concerns!  Use proven design patterns!  Follow OERA best practices!

44 © 2007 Progress Software Corporation 44 ARCH-11: Building your Presentation with Classes Relevant Exchange Sessions:  ARCH-1: Application Architecture Made Simple  ARCH-2: OERA Latest Thinking!  ARCH-7: A Class-based Implementation of the OERA  ARCH-12: Leveraging Design Patterns in ABL Applications For More Information, go to… PSDN: www.psdn.com/library/kbcategory.jspa?categoryID=289 OpenEdge Principles: Implementing the OpenEdge Reference Architecture

45 © 2007 Progress Software Corporation 45 ARCH-11: Building your Presentation with Classes Questions?

46 © 2007 Progress Software Corporation 46 ARCH-11: Building your Presentation with Classes Thank you for your time

47 © 2007 Progress Software Corporation 47 ARCH-11: Building your Presentation with Classes


Download ppt "ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha Kraljevic Principal TSE."

Similar presentations


Ads by Google