The Parameters property is useful when designing tools that interact with business objects-such as the business object browser that we'll look at later on-since the parameters for a factory can be determined at run time. This determination allows us to automatically instantiate factory objects.
Dim ocfEmployees As New cfEmployees Dim ocParams As New cParams Set ocfEmployees = New cfEmployees Set ocParams = ocfEmployee.Parameters ' Do stuff with ocParams.
So far, we've concentrated mainly on the factory objects; now it's time to examine in greater detail the construction of the worker objects.
Factory objects all have the same interface. Worker objects all have unique interfaces. The interface of our sample Employee worker object is shown below.
cWorker Employee Interface
|ID||Unique string identifier for the worker object|
|Salary||Employee gross salary|
|Department||Department the employee works in|
|Create||Creates a new worker object|
Creating a worker
As we saw in the discussion of the factory object, creating a worker object involves passing the worker object a reference to the shared recordset and a reference to the factory's DAL object. This is what the worker does with these parameters:
Private oPicRecordset As cRecordSet Private lPiRowIndex As Long Private oPicDAL As cDAL Friend Sub Create(i_ocRecordset As cRecordSet, i_ocDAL As cDAL) Set oPicRecordset = i_ocRecordset Set oPicDAL = i_ocDAL lPiRowIndex = I_ocRecordset.AbsolutePosition End Sub
Why is this procedure so friendly? (That is, why is it declared as Friend and not as Public?) Well, remember that these worker objects are "Public Not Creatable" because we want them instantiated only by the factory object. Because the factory and workers always live in the same component, the Friend designation gives the factory object exclusive access to the Create method. Notice also that the worker objects store the row reference in the module-level variable lPiRowIndex.updated