1) A Namespace “Domain\Customer” with a Class “Model”
namespace MyDomain\Customer;
class Model { }
class Repository { }
namespace MyDomain\City;
class Model { }
class Repository { }
2) A Namespace “MyDomain” with a class “CustomerModel” ?
namespace MyDomain;
class CustomerModel { }
class CustomerRepository { }
namespace MyDomain;
class CityModel { }
class CityRepository { }
3) A Namespace “MyDomain\Customer” with a class “CustomerModel” ?
namespace MyDomain\Customer;
class CustomerModel { }
class CustomerRepository { }
namespace MyDomain\City;
class CityModel { }
class CityRepository { }
Or …
Our current environment use a PHP auto-load function that include file this way
$o = new MyDomain\Customer\Model.php
Will load the file
MyDomain\Customer\Model.php
Actually where I work we use example #1 that cause all file to be named Model.php. It’s a bit hard to to know what model is open without looking full path in Eclipse IDE.
Class names should express what they represent. A class called
Modelsounds like if it is a general class for certain models.CustomerModel, in contrast, says that it is the model of a customer. Customer also is not clearly defined when you see it out of the context, but in your particular application, the meaning is clear. So I would suggest to choseCustomerModel.If you only have
ModelandRepositoryclasses, it wouldn’t be good to declare a whole namespace only for those two classes, especially when you would define several two-class namespaces. Maybe separate the models from the repositories?