"Andrea Raimondi" wrote
Quote
TCustomer = class( TClient )
public
property Orders[ Index : Integer ] : TOrder;
end;
One problem with this that it really turns the customer and collection into
historical items--do you really want the customer loading every order ever
placed just to look at what's current? Think out the usage pattern here--you
don't want the system bogging down as completed orders accumulate, nor do
you want to end up with
TCustomer = class( TClient )
public
property Orders[ Index : Integer ] : TOrder;
property OpenOrders[ Index : Integer ] : TOrder;
property ClosedOrders[ Index : Integer ] : TOrder;
property OverdueOrders[ Index : Integer ] : TOrder;
property OrdersPendingCreditApproval[ Index : Integer ] : TOrder;
{etc}
end;
Might be better not to give the client an order collection at all, so as not
to burden it with all these issues:
ClientsOrders := TOrderCollection.Create;
ClientsOrders.LoadCollection('LoadCurrentForCust', [Cust.ID]);
This makes your load process a lot more flexible and decouples orders and
customers. The fact that a customer is a collection membership criteria
(that is, a navigation point) for orders in the database does not mean that
it has to or should be an orders collection owner. (Tip of the conceptual
hat to Joanna).
Quote
I should probably declare Client as an order property, so that
I can access the client of the order... or not?
All above was just abstract OO-thinking--now a bit on the specific domain
model. Rather than
Order.Client
I'd suggest
Order.Acount
Linking orders directly to customers is a matter of how complete/complex
your object model is. For a business with repeat customers and standing
customer relationships, an order would normally be related to an account,
which is in turn related to one or more responsible parties--admin contact,
purchasing agent, payer, etc. Parties are an abstract concept (or
interface), since a party can be either a person or organization (I can
establish an account for John Doe, or an account for Fotheringay Accoustic
Supply, Inc.).
This allows you to do things like have orders from the same client ship to
different addresses, have a single payee for multiple accounts, or have a
customer place orders for multiple accounts.
bobD