Creating new Business Objects
Start by learning to understand the basic architecture of the wwBusiness class which is the base of all business objects you will create.
Creating a new instance of a business object involves subclassing the wwBusiness class and setting a few properties in the constructor of the object.
The process consists of:
- Adding a reference to the wwBusiness DLL to your project
- Creating a new class and inheriting it from wwBusiness
- Adding the Westwind.BusinessObject namespace
- Implementing the constructor
Adding a reference
To add the wwBusiness.dll to your project go to the References section of the project and either add the DLL directly from the wwBusiness build directory or alternately you can open the wwBusiness project in your current solution and then add a reference to that project.Creating a new Class
Create a new class in your project. By default classes inherit from Object which is shows no inheritance on the Class descriptor. Change this to:public class busYourBusObject : wwBusiness
Add the namespace
You will also need to add the wwBusiness namespace to make sure that all members and related object members show up properly in your code via intellisense and compile properly. Do this by adding:using Westwind.BusinessObject;
above the namespace reference.
Implementing the constructor
Finally you need to implement a constructor and point it at a ConnectionString and ConnectType and database TableName at a minimum.The following snippet demonstrates all of the steps:
namespace Westwind.WebStore
{
public class busInvoice : wwBusiness
public busInvoice()
{
this.ConnectType = App.Configuration.ConnectType;
this.ConnectionString = App.Configuration.ConnectionString;
this.NewRowBlankValues = true;
this.Tablename = "wws_invoice";
this.PkField = "pk"; // defaults to pk
this.PkType = PkFieldTypes.intType; // defaults to intType
}
}
In the Web Store you can always use the App.Configuration object to retrieve the connection string and type. In other applications you may have to manually set these values or retrieve them by another means. NewBlankRowValues is optional but used in all objects of the store - this sets all fields to default blank values rather than nulls to avoid update problems. Finally the tablename is explicitly set and mapped to an underlying database table that is used as the default table updated by this business object if you don't override Load, GetBlankRecord and Save methods.
Once you've created the class you can easily instantiate it with:
busInvoice = new busInvoice();
Creating a Factory method
Although direct instantiation is easy, it's a good idea to create an intermediary method to provide an instance. This is known as a Factory and the Web Store provides a WebStoreFactory class for this. This class provides static members for each of the classes in the store as to provide a single point of object creation. This is useful if you at some later point decide to subclass a business object and want to have the new subclass be used throughout the application.To create a Factory method you'd use the WebStoreFactory class for example and implement:
public static busInvoice GetbusInvoice()
{
return new busInvoice();
}
If at some point in the future you decide to subclass busInvoice into busMyNewInvoice you change that to:
public static busInvoice GetbusInvoice()
{
return (busInvoice) new busMyNewInvoice();
}
which makes sure that existing code still works just fine. Anytime you need the new functionality you can then simply case the object to your specific business object type:
busMyNewInvoice Invoice = (busMyNewInvoice) WebStoreFactory.GetbusInvoice();
© West Wind Technologies, 1996-2018 • Updated: 09/05/05
Comment or report problem with topic