In Java and ActionScript3.0 we use namespaces
based on the directory path, I see a lot of use of namespace
, but are not based on the path of the "location" class in the folder.
I searched a lot if there was any kind of organization that has that "recommendation" for PHP, the PSR-4, but for C ++ I did not find any recommendations, I know it should be trivial, but I think a minimum of organization, size of the team or be a personal project can be a good way, in the case the intention is not to use namespaces
in all classes, only in isolated libs that I will reuse for various applications.
Is there something like this for C ++, an "official" design pattern?
If it does not exist, I thought of doing something like this:
-
./fornecedor/categoria/foo.h
namespace Fornecedor { namespace Categoria { class Foo() { public: Foo(); }; }; };
-
./fornecedor/categoria/foo.cpp
#include "foo.h" using namespace Fornecedor::Categoria; Foo::Foo() { ... }
In this example above:
- The class name is associated with the file name
- Files and folders are always in lowercase (lowercase letters)
- Category would only be to divide the use of classes, for example
fornecedor/matematica/soma.cpp
andfornecedor/matematica/divisao.cpp
This is just an idea, would it be a good way?