I always wondered how I should write and which design template to use to create lists of objects.
First of all, consider that I have a Customer class and an Order class. I would like to receive all Orders owned by the User.
I would like $ oCustomer-> getOrders (); to return an array of Order objects.
Basically, I thought:
The OrderManager class, which is singleton and has the ability to extract order data from the storage engine and create Order objects. But I read everywhere that this is bad practice, so this does not seem to be a good idea.
Using static methods in the Order class, such as getOrders (args), but I'm not sure what the real point of static methods are.
Using Factory (which I never used, unfortunately) to handle object creation (maybe I need some examples)
Using a method in an Order object. This seems like the worst option in the world since I really don't think the object should be able to return its own collection.
It looks like a very simple task that I assume. But I could not find someone who would give the โrightโ way to do this. I'm fine with adding other classes, etc. (For example, DataMappers, Gateways, aso ... for search processing and matching), but I really don't want to talk to them in my business logic.
Thanks in advance.
source share