3

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.

Yanik Lupien
  • 120
  • 1
  • 5

1 Answers1

2

Class names should express what they represent. A class called Model sounds 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 chose CustomerModel.

If you only have Model and Repository classes, 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?

Yogu
  • 9,165
  • 5
  • 37
  • 58
  • Yes it's probably a good idea to separate the models from the repositories because all repository class should implement the storage specific logic. Thank you for your answer. – Yanik Lupien Dec 27 '11 at 14:18