Resources

Click TW6.1 Export or TW7 Export to download an export of some examples that demonstrate this design pattern. (coming soon)

Many examples are provided within this export, including the following model artefacts:

Business Object Model (Initialisers & Dummy Data)
SDCMAN Init Surf Board DAS
SDCMAN Init Surf Board List DAS
SDCMAN Dummy Surf Board DAS
View (Drop Down List)
SDCMAN Get Recipient Drop Down List DAS
Integration
SDCMAN Create Table Correspondence Sent DAS
SDCMAN Create Correspondence Sent DAS
SDCMAN Read Correspondence Sent DAS
SDCMAN Delete Correspondence Sent DAS

Design Pattern

Naming Convention Example
<Prefix><Body>DAS SDCMAN Create Surf Board DAS

Within an Object Oriented (OO) programming language like Java both data and behaviour are combined within an object. Within OO the principle of encapsulation means that data is only accessed via operations defined for the object. The Data Access Service design pattern is used to support encapsulation within Teamworks, where data and behaviour are defined within variables and services respectively. A number of Data Access Services may be defined for a single variable. Both variables and Data Access Services may be defined within each of the view layer, the business object model layer and the integration layer of the architecture, as illustrated in Figure 1. Data Access Services may be further categorised as follows.

TW App Arch (Artefacts)

Initialisers

Naming Convention Example
<Prefix>Init<Variable Type>DAS SDCMAN Init Surf Board DAS

Variable types provide a definition of how data is structured, but they do not actually hold data values. A variable is created using Javascript. Once the variable is created then it can be used to store data. Data Access Services may be used to initialise variables and assign default values using Javascript.

DAS - Initialiser

Javascript:
tw.local.surfBoard = new tw.object.SDCMAN_SurfBoard();
tw.local.surfBoard.colours = new tw.object.listof.String();

This promotes re-use and improves maintainability, as Javascript constructs are minimised and defined in one place only.

Several initialisers may be defined for the same business object depending on how much data is pre-populated during the initialisation. The default initialiser, as illustrated above, simply constructs the basic structure required to hold the data. Other initialisers provide input parameters that are used to either fully or partially load the business object with data. These initialisers should use the default initialiser to create the basic object before populating it with data.

For example:

Naming Convention Example
<Prefix>Init Loaded<Variable Type>DAS SDCMAN Init Loaded Surf Board DAS

Service: SDCMAN Init Loaded Surf Board DAS
Input Parameter: length (Decimal)
Input Parameter: colours (String) (List)
Input Parameter: logo (String)
Output Parameter: surfBoard (SDCMAN_SurfBoard)

Javascript:
tw.local.surfBoard.length = tw.local.length;
tw.local.surfBoard.colours = tw.local.colours;
tw.local.surfBoard.logo = tw.local.logo;

Dummy Data

Naming Convention Example
<Prefix>Dummy<Variable Type>DAS SDCMAN Dummy Surf Board DAS

Dummy data may be required for either testing purposes or to stub out integrations. Data Access Services can be used to set up dummy data for variables. For example:

DAS - Dummy Data


Service: SDCMAN Dummy Surf Board DAS
Output Parameter:surfBoard (SDCMAN_SurfBoard)

Javascript:
tw.local.surfBoard.length = 6.5;
tw.local.surfBoard.colours[0] = "yellow";
tw.local.surfBoard.colours[1] = "red";
tw.local.surfBoard.logo = "Surf Dudes";

Helpers

Naming Convention: <Prefix><Body> DAS
Example:
SDCMAN Determine Routing for Best Sales Opportunity DAS
SDCUSSM Get Marketing Details for Surf Board DAS
SDCMAN Calculate Cost of Surf Board DAS
SDCMAN Load Surf Board DAS
SDCMAN Save Surf Board DAS

Helpers may reside in any layer, but are predominantly used within the Business Object Model layer. They may be used in a variety of ways.
Some helpers may be used to enforce a business rule. For example:

Service: SDCMAN Determine Routing for Best Sales Opportunity DAS
Input Parameter: surfBoard (SDCMAN_SurfBoard)
Output Parameter: assignedTo (String)

Some helpers may be used to locate parts of the complex variable using indexes (See Indexes design pattern). For example:

Service: SDCUSSM Get Marketing Details for Surf Board DAS
Input Parameter: surfBoard (SDCMAN_SurfBoard)
Input Parameter: marketingIndex (Integer)

Some helpers are used to work out derived data. For example:
Service: SDCMAN Calculate Cost of Surf Board DAS
Input Parameter: surfBoard (SDCMAN_SurfBoard)
Output Parameter: cost (Decimal)

Javascript:
tw.local.cost = tw.local.surfBoard.pieceCost + tw.local.surfBoard.labourCost;

Some are used for persistence (See PS Persistence Framework). For example:
Service: SDCMAN Load Surf Board DAS
Input Parameter: surfBoard (SDCMAN_SurfBoard)
Output Parameter: surfboard (SDCMAN_SurfBoard)

Service: SDCMAN Save Surf Board DAS
Input Parameter: surfBoard (SDCMAN_SurfBoard)
Output Parameter: surfboard (SDCMAN_SurfBoard)

Helper services may range from simple services comprising one line of Javascript to more complex services comprising loops and nested services. It is good practice to define services for even the simplest logic, as they will probably be reused in the future and will improve productivity and maintenance.

Integration

Naming Convention Example
<Prefix> Create <Variable Type> DAS SDCMAN Create Surf Board DAS
<Prefix> Read <Variable Type> DAS SDCMAN Read Surf Board DAS
<Prefix> Update <Variable Type> DAS SDCMAN Update Surf Board DAS
<Prefix> Delete <Variable Type> DAS SDCMAN Delete Surf Board DAS

Integration data access services reside within the integration layer and manipulate data from back-end legacy systems or data sources. Typically they perform persistent CRUD operations, i.e. Create, Read, Update and Delete. A create service will create a brand new business entity. A read service will retrieve business data based on some criteria. This may return a single business entity or a list of business entities. An update service will modify attributes of an existing business entity. A delete service will remove a business entity.

DAS - Integration

The preceding figure illustrates a typical integration data access service used to retrieve data from an SQL data base.

Service: SDCMAN Read Surf Board DAS
Input Parameter: surfBoardSku (String)
Output Parameter: surfboard (SDCMAN_SurfBoard)

A decision gate is used to check whether the integration is available to allow the service to be used off-line for testing purposes. An EPV provides a switch to indicate which integrations are available, as illustrated in the following.

DAS - Integration - Decision Gateway

If the integration is not available then the dummy DAS is used to return test data. If the integration is available then the data is retrieved from the back-end data source and the result is used to construct and populate the business object being returned. The example illustrated here demonstrates how an SQL query may be modelled, but the integration DAS could also be used for other integration technologies such as web services.

Original author: Dennis Parrott

Join The Discussion

Your email address will not be published. Required fields are marked *