I have been assigned the task of refactoring a legacy database application and I am trying to create objects that incapsulate the old code. It is the first time I use real OODesign, for now I just used OO to encapsulate some legacy login and refactor a subset of functionalities from an application. (Now it is the classic client server app with all the business logic in the UI, the idea is to make it multilayer in order to use the clients against an application server and eventually write a web interface.)
I'll make an simplified example to explain what I want to accomplish:
I have many instances of this class:
type
TCustomer = class(TObject)
private
FOrders: TList<TOrder>; // or how do implement this?
// the idea is that the TCustomer "owns" the TOrder, anyway in the
// legacy DB I just have an orders table with FK to the customer table
// not the contrary.
// But if I do that the Customer object "loses" the TOrders???
[...] // Many other fields
public
[...]
end;
How do I query the Orders of all the customers? Imagine I want to query all the orders from September 2007.
If I have 10000 TCustomer
objects I don't want for sure to create them all (that means retrieveing them all from the database: I would retrieve too many info I don't need).
In the current software of course it is done with a simple query to the orders table.
But how this is accomplished in the OO world?
Which is the approach you suggest me?
Moreover: in refactoring a this kind of database applications do you suggest using an ORM (that means creating a new database and migrating all the data) or simply use existing DB (that is not bad in my case)?