| West Wind Web Store |
| Introducing wwStore Business Objects |
As a result you'll find that there is very little business logic in the Web Connection specific portion of the Web application. The offline viewer has a number of features that are specific to West Wind Technology's business needs and thus has a little more code, but even this custom code uses business objects extensively to perform these tasks.
All of the BOs are derived of the wwBusiness class which provides base functionality for loading, saving, adding of individual records in these business objects. It also supports creating of tables and a number of features related to creating new records and administrating the table(s) the object presides over. By default wwBusiness maps to an underlying table, but this behavior is not required. You can create more abstract and compound objects easily and override the base behaviors for methods such as Load and Save easily.
For example, the cInvoice class is a compound object that manages and handles multiple objects such as Customer, LineItems and Invoice objects. The appropriate methods are overridden to provide this functionality and call these additional business objects to perform their own Save and Load operations and so on.
loItem = CREATE("cItem")
loItem.GetItembySku("WCONNECT")
oItem = loItem.oData
? oItem.SKU
? oItem.Descript
oItem.Descript = "New Value"
oItem.Save()
Most objects are simple like the cItem object which map almost directly to an underlying table. Each business object has an oData member that contains the actual fields of its master table. However, you can extend business objects as you see fit. For example, when you look at the invoice object you'll see that that object has additional references to other business objects like cCustomer and cLineitems providing compound functionality. For example:
loInv = CREATE("cInvoice")
loInv.Load(1000) && Pk
? loInv.oCustomer.LastName
? loInv.oLineItems.aRows[1].sku
Because data is stored in object properties it's very easy to display that data in template pages without having to write code in those pages. Any code that does need to be written to access the objects is very simple since the objects are self contained.
The business object supports loading objects and querying which is nice for retrieving data without explicitly accessing the underlying tables.The query and find methods can return data either as a table, XML or an ADO recordset. For simple operation the base methods provide a lot of functionality without any new code requirements.
To extend functionality and common operations the business object is extended with custom methods. These methods can be as simple as running a common query (sort of like a view that's not bound to a specific database) , or much more complex operations like for example saving an invoice to disk.
In the wwStore application the master object is an invoice object which provides functionality to load and save all of its related items through its methods. So saving the invoice causes the customer and lineitems also to be saved. The entire operation is atomic and wrapped into a TRANSACTION to allow ROLLBACKs in case something in the middle of this complex update fails.
The whole idea is to build objects that expose interfaces that are easy and logical to use from calling code yielding fairly self-describing code. After all you can probably figure out what:
oInv.Load("InvoiceNo")does.
The benefit of this architecture is that you now have an object that's easy to manipulate without a data dependency, that can be passed around easily and if necessary can be persisted into XML for easy transfer over the wire for example to download orders over the Internet.
Last Updated: 06/02/03 |
Send topic feedback