Subclassing the Business Objects

If you plan on making changes to the business rules it's recommended you spend a little time getting familiar with the business object framework that the Web Store is based on. The wwBusiness class is easy to pick up and work with after you have a basic understanding of its relatively simple concepts of retrieving and updating data.

Making Changes? Subclass the base objects!

The first step in making changes is to subclass the base object you want to change, so that the changes you make don't overwrite existing code. The idea is if the framework changes later on your code sits on top of the framework so framework update won't overwrite any changes you've made.

Subclassing is a two step process:

  • Actually subclassing the Web Store business object
  • Changing the WebStoreFactory load method to use your subclass

All of the Web Store business objects are stored in the WebStoreBusiness project. To subclass create a new class in this project. I will use the busInvoice object as an example and subclass it here for West Wind's operation. To do this I start by creating a new class - busInvoice_WestWind.

using System;
using System.Data;

namespace Westwind.WebStore
{
	/// <summary>
	/// West Wind Specific subclass of the Invoice object
	/// </summary>
	public class busInvoice_WestWind : busInvoice
	{
		public override decimal CalculateShipping() 
		{
			... my code here to override the shipping behavior
		}

	}
}

Since we're subclassing from an existing business object we don't need to set up a constructor with the common configuration settings (connection string, connection type etc) as we're inheriting this from the parent class.

Next we need to change the WebStoreFactory class so that it uses our new class instead of the default busInvoice class. The Web Store always uses this factory method.

So instead of direct instantiation:

busInvoice Invoice = new busInvoice();

it calls the factory method:

busInvoice Invoice = WebStoreFactory.GetbusInvoice();

To make it return our custom instance just change the WebStoreFactory.GetbusInvoice() method to:

public static busInvoice GetbusInvoice() 
{
	return new busInvoice_WestWind();
}

And voila the store now always uses your custom class for all operations. If you're only overriding existing methods or properties you don't need to do anything else. If you add new methods or properties to your objects however you have to make sure to cast the object to the proper type. For example:

busInvoice_WestWind Invoice = (busInvoice_WestWind) WebStoreFactory.GetbusInvoice();
Invoice.MyCustomProperty = "Custom value";



© West Wind Technologies, 1996-2018 • Updated: 12/29/03
Comment or report problem with topic