简体   繁体   English

类名中的模块名

[英]Module name within class name

While refactoring my User class, I created a new UserService class. 在重构User类时,我创建了一个新的UserService类。 After some work I decided to move all user related operations into a new microservice which resides under the "User" namespace. 经过一些工作后,我决定将所有与用户相关的操作移到位于“用户”名称空间下的新微服务中。

My first move would be having User::UserService which seems a little bit redundant, but somehow User::Service also sounds fishy or plain lazy typing. 我的第一步是让User :: UserService看起来有点多余,但是不知何故User :: Service听起来也很脏或很懒惰。

What is the common naming convention on popular Ruby gems for this case 在这种情况下,流行的Ruby gem的通用命名约定是什么?

After some trials my current choice is the seemly redundant User::UserService 经过一番试验之后,我目前的选择是看似多余的User :: UserService

The reason is that UserService is the first natural move of refactoring and introducing too early the User:: namespace might be a symptom of over-design. 原因是UserService是重构和过早引入User ::名称空间的自然而然的第一步,这可能是过度设计的征兆。

As the code matures renaming UserService to User::Service everywhere is an unnecessary pain, specially since it is possible to create an alias on the global namespace. 随着代码的成熟,将UserService重命名为User :: Service到处都是不必要的麻烦,特别是因为可以在全局名称空间上创建别名。

Inside the User namespace using just Service is a tad ambiguous, and having to type long redundant names from other namespaces might be an alarm about the module coupling. 在仅使用ServiceUser命名空间中,有点含糊,必须从其他命名空间键入冗长的冗余名称可能是有关模块耦合的警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM