D
D
devastation_kvlt2018-10-15 14:31:29
PHP
devastation_kvlt, 2018-10-15 14:31:29

Why duplicate the namespace in the class name?

In popular frameworks, it is customary to name classes like this:

App\Repositories\UserRepository
App\Controllers\UserController

Why not?
App\Repositories\User
App\Controllers\User

After all, it is more concise. What are the arguments in favor of such a name?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2018-10-15
@miraage

And when importing both classes, what will you do? That's why they are called unique names so that you can immediately distinguish one class from another. Moreover, this architecture (App\Repositories, App\Controllers) is not used in all projects. Therefore, it is logical to specify both the functional component (service, controller) and the domain one (user, app, article).

I
Ivan Shumov, 2018-10-15
@inoise

Frameworks are written not by 1, not 2, but by a large number of people. Therefore, a universal naming convention is created. In addition, different files can be located in the same directory under the same namespace, such as UserRepository and UserModel.

K
Kirill Gorelov, 2018-10-15
@Kirill-Gorelov

Habr recommend. Should answer your question. It's good that you're interested.
This article helped me a lot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question