I wrote a little framework a while ago and i choose to use the first solution you propose.
Keep aggregate roots at the root of the domain model:
Why?
Actually I asked myself the same question you're asking today and after a bit of discussion with my team mates we agreed that it felt more logical not to repeat the class name in the namespace.
Let's see how to instanciate your classes with solution n°2
Customer\Customer
Customer\Address
You will have to write :
$customer = new Customer\Customer();
$address = new Customer\Address();
You can see the repetition right? It kind of doesn't feel right to me.
In my opinion it's like writing
$customer->getCustomerId();
Why repeat Customer in the method name? We know it's the customer's id since we're using a Customer object.
Another "bad thing" with this model is the impossibility to use reserved keyword as class name.
For exemple, using the pear convention you could have had the class
Customer_Abstract
Located at Customer/Abstract.php which is ok to me but if you try to translate it using namespace you will have
namespace Customer;
class Abstract {}
which results in a fatal error. So again you will have to repeat the domain in the class name :
namespace Customer;
class AbstractCustomer {}
$customer = new Customer\AbstractCustomer();
Now let's see how to instanciate your classes with solution n°1
Customer
Customer\Address
You will write :
$customer = new Customer();
$address = new Customer\Address();
We don't have to repeat Customer twice anymore to instanciate the Customer class. However it is still clear that Address is related to Customer.
That's why I choose to use this model.
EDIT : Zend Framework 2 use this convention too
namespaces
are specially usefull when projects are big in dimension, and / or when there's a lot of people involved in their development / maintenance. The basic principle ofDDD
is to keep everything simple and to the point, wich means that there will hardly exist any type of colisions inside the appliction. So .. arenamespaces
real necessary in this case? – Discount