Step 3: Define the Business Operations

Defining an application's business operations involves:

Identify Operations that Reflect Business Processes

The DNA PurchaseOrder application defines business operations that reflect the process of selling books. These operations can be organized into four groups:

Tables 6-9 describe each of the operations defined by the DNA PurchaseOrder application.

Table 6. Account Operations Defined by the DNA PurchaseOrder Application

Operation Description
Create Creates a new account in the underlying Accounts database table. This operation is only available to application "Administrators."
CreateRecordset Creates a recordset containing detailed account information based on user-supplied selection criteria.
DecrementBalance Decrements the balance of an account by a user-defined amount.
Destroy Deletes an account from the underlying Accounts database table. This operation is only available to application "Administrators."
IncrementBalance Increments the balance of an account by a user-defined amount.
Modify Changes an existing account in the underlying Accounts database table. This operation is only available to application "Administrators."

Table 7. Inventory Operations Defined by the DNA PurchaseOrder Application

Operation Description
Create Creates a new inventory item in the underlying Inventory database table. This operation is only available to application "Administrators."
CreateRecordset Creates a recordset containing detailed inventory item information based on user-supplied selection criteria.
DecrementQOH Decrements the quantities on hand of an inventory item by a user-defined number.
Destroy Deletes an inventory item from the underlying Inventory database table. This operation is only available to application "Administrators."
IncrementQOH Increments the quantities on hand of an inventory item by a user-defined number.
Modify Changes an existing inventory item in the underlying Inventory database table. This operation is only available to application "Administrators."

Table 8. LineItem Operations Defined by the DNA PurchaseOrder Application

Operation Description
Create Creates a new line item in the underlying LineItems database table.
CreateRecordset Creates a recordset containing detailed line item information based on user-supplied selection criteria.
Destroy Deletes a line item from the underlying LineItems database table.
DestroyByPurchaseOrder Deletes all of the line items associated with a particular purchase order.
Modify Changes an existing line item in the underlying LineItems database table.

Table 9. PurchaseOrder Operations Defined by the DNA PurchaseOrder Application

Operation Description
Cancel Reverses the effects of creating a purchase order.
Create Creates a new purchase order in the underlying PurchaseOrders database table.
CreateRecordset Creates a recordset containing detailed purchase order information based on user-supplied selection criteria.
Destroy Deletes a purchase order from the underlying PurchaseOrders database table.
Modify Changes an existing purchase order in the underlying PurchaseOrders database table.

Define and Publish the Syntax for Each Business Operation Request

Once the various business operations have been identified, request syntaxes for each must be defined and published, so perspective clients will know how to properly format requests for service. Developers are free to define and publish their business operation request syntaxes however they see fit (for example, COM interfaces, XML-encoded MSMQ messages, and so on). The request syntaxes for the DNA PurchaseOrder application are defined using Component Object Model (COM) interfaces, and published using a COM type library, which contains all the information perspective clients need to issue properly formatted requests.

When defining request syntaxes for business operations, developers must take special care to ensure all of the data required to perform each individual business operation can be delivered with minimal trips across the network. Typically this involves supplying the required data as individual function arguments, or supplying the required data using a single ActiveX Data Objects (ADO) disconnected recordset, variant array, or persistable object. The DNA PurchaseOrder application uses the persistable object approach, in which "special" objects are used to represent the data required by individual business operations. When a business operation request is issued, the operation's corresponding special object marshals its internal state information to a byte stream, which is somehow transmitted across the network, where it is unmarshaled and used to initialize a local instance of the special object. The DNA PurchaseOrder application defines four COM interfaces that describe the data required to perform its various business operations:

Table 10. The IAccount Interface Is Used to Marshal the Data Required to Perform Account Operations.

Property/method Data type Description
(P) ID Long Uniquely identifies each account.
(P) FirstName String The first name of the account owner.
(P) LastName String The last name of the account owner.
(P) AddressLine1 String The address of the account owner.
(P) AddressLine2 String The address of the account owner.
(P) City String The city of the account owner.
(P) State String The state of the account owner.
(P) Phone String The phone number of the account owner.
(P) Email String The e-mail address of the account owner.
(P) Balance Currency The balance of the account.
(P) Limit Currency The credit limit of the account.
(M) MarshalToPropertyBag Byte() Marshals the object into a property bag and returns the bag's contents as an array of bytes.
(P) Valid Boolean Reflects whether the object has any invalid properties.

Table 11. The IInventory Interface Is Used to Marshal the Data Required to Perform Inventory Operations.

Property/method Data type Description
(P) ID Long Uniquely identifies each inventory item.
(P) Description String A description of the item.
(P) Price Currency The price of the item.
(P) QOH Long The quantity on hand.
(M) MarshalToPropertyBag Byte() Marshals the object into a property bag and returns the bag's contents as an array of bytes.
(P) Valid Boolean Reflects whether the object has any invalid properties.

Table 12. The ILineItem Interface Is Used to Marshal the Data Required to Perform Line Item Operations.

Property/method Data type Description
(P) ID Long Uniquely identifies each line item.
(P) PurchaseOrderID Long The unique identifier of the purchase order to which the line item belongs.
(P) Item IInventory The inventory item being purchased.
(P) Price Currency The price for which the inventory item is being sold.
(P) Quantity Long The number of inventory items being purchased.
(M) MarshalToPropertyBag Byte() Marshals the object into a property bag and returns the bag's contents as an array of bytes.
(P) Valid Boolean Reflects whether the object has any invalid properties.

Table 13. The IPurchaseOrder Interface Is Used to Marshal the Data Required to Perform Purchase Order Operations.

Property/method Data type Description
(P) ID Long Uniquely identifies each purchase order.
(P) AccountID Long The account to which the order should be charged.
(P) OrderDate Date The data the purchase was made.
(P) SubTotal Currency The sum of (the quantity of each line item x the price of each line item) the purchases.
(P) ShippingHandling Currency The cost to ship the order.
(P) TaxRate Double The percentage of tax to be levied.
(P) Tax Currency The sum of (SubTotal + ShippingHandling) x TaxRate.
(P) Total Currency The sum of (SubTotal + ShippingHandling + Tax).
(P) ShipToFirstName String The first name of the order recipient.
(P) ShipToLastName String The last name of the order recipient.
(P) ShipToAddressLine1 String The address of the order recipient.
(P) ShipToAddressLine2 String The address of the order recipient.
(P) ShipToCity String The city of the order recipient.
(P) ShipToState String The state of the order recipient.
(P) ShipToPhone String The phone number of the order recipient.
(P) ShipToEmail String The e-mail address of the order recipient.
(P) LineItems ILineItems The ILineItems of the object that manages the purchase order's individual line items.
(M) MarshalToPropertyBag Byte() Marshals the object into a property bag and returns the bag's contents as an array of bytes.
(P) Valid Boolean Reflects whether the object has any invalid properties.

The DNA PurchaseOrder application also defines the ILineItems interface, which provides an easy way to manage the various individual line items associated with a particular purchase order.

Table 14. The ILineItems Interface Is Used to Manage the Various Individual Line Items Associated with a Particular Purchase Order.

Property/method Data type Description
(M) Add Boolean Adds a line item to the purchase order.
(P) Count Long Returns the number of line items associated with the purchase order.
(P) Item ILineItem Returns line item #n from the purchase order.
(M) Remove Boolean Removes line item #n from the purchase order.

To define the COM interfaces that clients will use to request the business operations defined by the DNA PurchaseOrder application

  1. Start Visual Basic if it's not already running.

  2. From the File menu, select New Project.

  3. Select ActiveX DLL from the New Project window and click OK.

  4. From the Project menu, select Project1 Properties, type POInterfaces in the Project Name text box, and click OK.

  5. From the Project menu, select References, place a check mark next to Microsoft ActiveX Data Access Objects 2.1 Library in the Available References list box, and click OK.

  6. Create eight additional class modules (for a total of nine) to contain the interface definitions, and name them IAccount, IAccountExec, IInventory, IInventoryExec, ILineItem, ILineItemExec, ILineItems, IPurchaseOrder, and IPurchaseOrderExec interface definitions.

  7. Define each interface using the code in Listings 6-14.

Once all of the interfaces have been defined, save your work, and compile the ActiveX DLL into POInterfaces.dll. POInterfaces.dll will contain all the request syntaxes for the various business operations defined by the DNA PurchaseOrder application.