1

I'm having some trouble working this one out, probably more than I should. This is a pretty large project, with a very clearly defined structure, with no obvious problems, but I can't seem to figure out the optimal solution for this case, even after reading several convention documents and such.

For example, given the following namespace:

\vendor\core\lib\view;

Obviously it refers to a "view" namespace...which technically also has a 'view' class in it:

\vendor\core\lib\view\view

This is clearly not ideal, but I can't come up with a better way to name these. Take for example the cache namespace:

\vendor\core\lib\cache;

Same deal, the cache class becomes confusing when inside this namespace:

\vendor\core\lib\cache\cache;

Should I just move these 'core' classes from their namespaces, and put them in the parent namespace?

\vendor\core\lib\cache (class)
\vendor\core\lib\cache\adapter\redis (class)

Or is there a better term to refer to these types of classes?

Pardon my circularity, it's a bit late and my head's not quite working in optimal condition.

migrated from stackoverflow.com Sep 14 '11 at 10:20

This question came from our site for professional and enthusiast programmers.

  • It's difficult to decipher what you're asking. – Herbert Sep 14 '11 at 2:33
2

By convention, class names should be uppercase and namespaces lowercase, so it's not "confusing" to do what you're doing:

use \vendor\core\lib\cache\Cache;
  • 2
    It may not be confusing, but it is a little untidy. If Cache is the only class in the cache namespace, then does it really need it's own namespace? \vendor\core\lib\Cache would be more appropriate. Alternatively, if there are more than one class in cache namespace, is the name cache really appropriate? – Gavin Coates Sep 14 '11 at 10:49
  • By convention, class names should be uppercase and namespaces lowercase - This is not the case (pun intended). – Unflux Mar 20 '18 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy