ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha...
-
Upload
julia-garrett -
Category
Documents
-
view
223 -
download
1
Transcript of ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha...
ARCH-11: Building your Presentation with Classes
John SaddFellow and OpenEdge Evangelist
Sasha KraljevicPrincipal TSE
© 2007 Progress Software Corporation2 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
© 2007 Progress Software Corporation3 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
© 2007 Progress Software Corporation4 ARCH-11: Building your Presentation with Classes
OpenEdge Reference Architecture
PresentationPresentation
Business ComponentsBusiness Components
Data AccessData Access
Data SourcesData Sources
Co
mm
on
Infrastru
cture
Co
mm
on
Infrastru
cture
Enterprise ServicesEnterprise Services
© 2007 Progress Software Corporation5 ARCH-11: Building your Presentation with Classes
OpenEdge Reference Architecture
PresentationPresentation
Business ComponentsBusiness Components
Data AccessData Access
Data SourcesData Sources
Co
mm
on
Infrastru
cture
Co
mm
on
Infrastru
cture
Enterprise ServicesEnterprise Services
Presentation controls the user interface and requests data and other services
© 2007 Progress Software Corporation6 ARCH-11: Building your Presentation with Classes
Demo – What do we want to achieve?
© 2007 Progress Software Corporation7 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
© 2007 Progress Software Corporation8 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:
© 2007 Progress Software Corporation9 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:
© 2007 Progress Software Corporation10 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:
© 2007 Progress Software Corporation11 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 :
© 2007 Progress Software Corporation12 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
© 2007 Progress Software Corporation13 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
© 2007 Progress Software Corporation14 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
© 2007 Progress Software Corporation15 ARCH-11: Building your Presentation with Classes
Model-View-Controller versus Model-View-Presenter
ControllerController
ModelModel ViewView
PresenterPresenter
ModelModel ViewView
MVC – Model View Controller
MVP – Model View Presenter
© 2007 Progress Software Corporation16 ARCH-11: Building your Presentation with Classes
Presenter versus Passive View
PresenterPresenter
ModelModel ViewView
MVP – Model View Presenter
PresenterPresenter
ModelModel ViewView
MVP – Passive View
© 2007 Progress Software Corporation17 ARCH-11: Building your Presentation with Classes
Design Patterns – Composite pattern for Views
cd CompositeView
View
+ Add() : View+ GetChild() : Component+ Remove() : View+ Render()
Request
SimpleView
+ Render()
CompositeView
+ Add() : View+ GetChild() : Component+ Remove() : View+ Render()
forall g in children g.Render();
-children
1..*
© 2007 Progress Software Corporation18 ARCH-11: Building your Presentation with Classes
Design Patterns – Composite pattern for Presenters
cd CompositePresenter
Presenter
+ Add() : Presenter+ GetChild() : Component+ Operation()+ Remove() : Presenter
SimplePresenter
+ Operation()
CompositePresenter
+ Add() : Presenter+ GetChild() : Component+ Operation()
forall g in children g.Operation();
+ Remove() : Presenter
-children
1..*
© 2007 Progress Software Corporation19 ARCH-11: Building your Presentation with Classes
Example View
© 2007 Progress Software Corporation20 ARCH-11: Building your Presentation with Classes
The View with the Presenter and Model
VIEW
PRESENTER
MODEL
© 2007 Progress Software Corporation21 ARCH-11: Building your Presentation with Classes
Design Patterns – Back to the OERA
cd PresentationInOERA
Presentation Layer
Client Business Component
(Model)Presenter
View
CommonInfrastructure
Serv iceAdapter
1 1..*
1
1..*
1..*
1..*
© 2007 Progress Software Corporation22 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
© 2007 Progress Software Corporation23 ARCH-11: Building your Presentation with Classes
The Service Adapter and Service Interface
PresentationPresentation
Business ComponentsBusiness Components
Data AccessData Access
Data SourcesData Sources
Co
mm
on
Infrastru
cture
Co
mm
on
Infrastru
cture
Enterprise ServicesEnterprise ServicesClient session
AppServer session
Service AdapterService Adapter
Service InterfaceService 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
© 2007 Progress Software Corporation24 ARCH-11: Building your Presentation with Classes
Support for a Business Component Type
The Model
The role of the Model in the Architecture
Service AdapterClient Business Component
Data Instance
Client Business Component
Data Instance
Service AdapterClient Business Component
Data Instance
Client Business Component
Data Instance
Service Interface Business Component
© 2007 Progress Software Corporation25 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
© 2007 Progress Software Corporation26 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
© 2007 Progress Software Corporation27 ARCH-11: Building your Presentation with Classes
PresentationPresentation
Business ComponentBusiness Component
Data AccessData Access
Data SourcesData Sources
Enterprise ServicesEnterprise ServicesCBC
SalesRep
SalesRep
View1SalesReps
View2
Co
mm
on
Infrastru
cture
Co
mm
on
Infrastru
cture
Example: a data instance for SalesReps
Presenter
All SalesRepsSvc Adapter
SalesRep
SalesRep BE
All SalesReps
SalesRep DAO
BIND
© 2007 Progress Software Corporation28 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
© 2007 Progress Software Corporation29 ARCH-11: Building your Presentation with Classes
Order BE
PresentationPresentation
Business ComponentBusiness Component
Data AccessData Access
Data SourcesData Sources
Enterprise ServicesEnterprise Services Order
Order OrderLine
Co
mm
on
Infrastru
cture
Co
mm
on
Infrastru
cture
CBCOrder
View1Order
View2OrderPresenter
Order 1Svc Adapter
Orders
Order 1
CBC
Order 3
Order 3Order 5
Order 5 Order 5
Example: Sharing and reusing data instances
Order DAO
© 2007 Progress Software Corporation30 ARCH-11: Building your Presentation with Classes
Service Adapters Common InfrastructureThe Model
Client-side code hierarchies
componentbase.cls
clientcomponent.cls
beCustomer.cls
serviceadapter.cls
saCustomer.cls servicemanager.cls
manager.cls
factory.p
INHERITS
INVOKES
© 2007 Progress Software Corporation31 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.
© 2007 Progress Software Corporation32 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.
© 2007 Progress Software Corporation33 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.
© 2007 Progress Software Corporation34 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
© 2007 Progress Software Corporation35 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
© 2007 Progress Software Corporation36 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
© 2007 Progress Software Corporation37 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
© 2007 Progress Software Corporation38 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.
© 2007 Progress Software Corporation39 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
© 2007 Progress Software Corporation40 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 !!!
© 2007 Progress Software Corporation41 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
© 2007 Progress Software Corporation42 ARCH-11: Building your Presentation with Classes
Demo – What have we achieved?
© 2007 Progress Software Corporation43 ARCH-11: Building your Presentation with Classes
In Summary
Separate concerns! Use proven design patterns! Follow OERA best practices!
© 2007 Progress Software Corporation44 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
© 2007 Progress Software Corporation46 ARCH-11: Building your Presentation with Classes
Thank you foryour time