I am in the process or trying to re-model an existing application using an ORM and trying to adhere to DDD as much as possible.
Work order is the AR and has more than a dozen child entities. I intended on modeling this class like so:
class WorkOrder {
private $number = 0;
private $manual = '';
...
// Sub-Entities
private $consumables; // Collection (1:m)
private $dimensions; // Collection (1:m)
private $sequences; // Collection (1:m)
...
}
Now I would need a repository to load (and persist?) this aggregate root -- correct?
The repo would return one or more aggregates which when I access the sub-entities (through indirect getter/setters -- not dot-notation) will lazy load the information I am after???
I will have another class to act as a factory for creating work orders -- which is a detailed process and includes substantial business logic/validation rules...
But if the factory creates the work order aggregate does the repo just persist the AR?
This factory would have to query a third party service (through REST or otherwise) and basically build a snapshot of an approved document describing work scope.
So the repository encapsulates the ORM or which ever persistence layer I should choose?
Right now my file structure would look something like:
WorkOrder/
/Factory.php
/Aggregate.php
/Repository.php
/Entity/Header.php
/Entity/Shipping.php
/Entity/Warranty.php
/Entity/Certification.php
...
The repository would have methods like:
FindOneByTrackingNumber()
FindAllByCriteria()
save($root);
My factory would have methods like:
createWorkOrderFromRpi()
createWorkOrderFromCsv()
...
I have read through several articles and countless posts on here:
http://williamdurand.fr/2013/08/07/ddd-with-symfony2-folder-structure-and-code-first/
While the detail is excellent I need a second opinion on my own interpretation, please. :)
Regards, Alex