8

Which of the following naming conventions is most used/accepted, or which is most optimal for most projects? I'm having a hard time deciding.

Base class: \Model
Sub class: \Model\User

Base class: \Model\Model
Sub class: \Model\User

Base class: \Model\Base
sub class: \Model\User

So in other words, should I put the base class in the same namespace as the subclasses, and should I call it something constant like "base" or should it just have the same name as the namespace?

Daniel
  • 81
  • 1

3 Answers3

3

Honestly, I always put the base class in the same directory as the sub classes, inless the base class is intended as part of a multi-application framework, in which case it would go in a generic library library,

Antony Gibbs
  • 3,300
  • 1
  • 17
  • 12
1

Not sure how PHP handles namespaces/packages, but in other languages there are benefits to keeping things in the same packages. I'm thinking specifically, of the ability to use Java's default and protected access modifiers, or C++'s friend keyword. These might not be possible/as straightforward once you start separating abstracts into a different package from concretes.

Tom Tresansky
  • 19,364
  • 17
  • 93
  • 129
0

I like the Zend Framework naming convention. If it don't seems very easy at first, it's very maintainable.

http://framework.zend.com/manual/en/coding-standard.naming-conventions.html

Brice Favre
  • 1,511
  • 1
  • 15
  • 34