Business Logic in Microsoft Transaction Server Components

Microsoft Corporation

July 1997

Abstract

This article describes how to enact business logic in Microsoft® Transaction Server (MTS) components.

Component Granularity

The granularity of a component is determined by the number of tasks it performs. The granularity of a component affects performance, debugging, and reusability of your MTS components.

Fine-Grained Components

A fine-grained component performs a single task, such as calculating tax on a sales order. For example, a fine-grained component consumes and releases resources quickly after completing a task. Note that components that enact a single business rule can facilitate testing packages, because isolating individual tasks in components makes testing your applications easier. In addition, fine-grained components are easily reused in other packages. In the Classified Advertisement sample application, the Customers component performs a single task: adding a customer record to the database.

Example

Function Update(ByVal strEmail As String, _
ByVal bNewCust As Boolean, ByVal strContact As String,_
ByVal strPhoneNumber As String, _
ByVal strNightPhoneNumber As String)

    Dim ctxObject As ObjectContext
    Set ctxObject = GetObjectContext

    On Error GoTo ErrorHandler

' Code accesses the customer row from the database.
' Customer information is updated with information
' that was passed in.
'
    ctxObject.SetComplete

    Exit Function

This simple Customer component is efficient in its use of system resources (by passing parameters by value), easy to debug (single function), and also reusable in any other application in which customer data is maintained.

Coarse-Grained Components

A coarse-grained component is a component that performs multiple tasks. Coarse-grained components are generally harder to debug and reuse in applications. For example, a PlaceOrder component might add a new order, update inventory, and update customer information. PlaceOrder is a more coarsely grained component because it performs more “work” by adding, updating, and deleting customer, inventory, and order information.

Refer to “Holding State in Objects” for more information about components' shared resources.