I am contemplating a rather complex inplementation that calls for a factory
class that can instantiate a large number of specific business objects, each
of which share a set of common base business rules (e.g., Update, Delete,
etc.) as well as a set of object specific methods. Of couse, all of the
interfaces shall be defined in a common assembly for the client and server
components. Since all of these are remoted, presume that the interfaces are:
IBusinessFactory
IDataManager
ICustomerManager : IDataManager
ISalesOrderManager : IDataManager
Do I need to declare a specific factory method for each individual business
object, or (presuming all objects have exactly one primary key identifier)
could I use a single method to retrieve a specific business object and then
cast it appropriately?
Method 1:
ICustomerManager remoteCustomer =
IBusinessFactory.GetCustomer(customerID);
ISalesOrderManager remoteSalesOrder =
IBusinessFactory.GetSalesOrder(salesOrderID);
Method 2:
ICustomerManager remoteCustomer =
(ICustomerManager)IBusinessFactory.GetBusinessObje ct("Customer",
customerID);
ISalesOrderManager remoteSalesOrder =
(ISalesOrderManager)IBusinessFactory.GetBusinessOb ject("SalesOrder",
salesOrderID);
While I have to define the individual interfaces, this eliminates a large
amount of custom coding in the factory, and the server version of the
factory could event derive the database table name that acts as backing
store for the data object from the first parameter (which would not have to
be a string parameter -- it could be an enum or a typeof() value).
Are there any pitfalls or problems with this? I have not actually tried
coding this yet as some other things are pressing, and I realized that even
if the code permitted it there may be a more effective approach in C#/,Net.
-ken