如果一个类具有相同的名称作为命名空间? [英] Should a class have the same name as the namespace?

查看:291
本文介绍了如果一个类具有相同的名称作为命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计一个命名空间来保存一组类将处理的用户相关的多个不同的应用任务。 (注册,认证等)

I'm designing a namespace to hold a set of classes that will handle user related tasks for a several different applications. (Log-in, authenticate etc)

现在的问题是命名空间将被称为 Fusion.User 但它需要一个类有意义调用该命名空间用户

The problem is the namespace will be called Fusion.User but then it requires a class in that namespace that makes sense to call User.

你应该有一个类具有相同的名称作为命名空间?还是我采取了错误的方式在这里?

Should you have a class with the same name as the namespace? Or am I taking the wrong approach here?

推荐答案

有以同样的方式作为名称空间(封装)命名的类可能导致以为类是中央的包。但是,如果我得到它的正确使用是在你的情况只是一个数据对象。

Having class named in the same way as the name space (package) may lead to a thought that class is central to the package. But if I get it correctly User is just a data object in your case.

据我看你有2个选择:

  1. 在不同的命名你的名字空间例如Fusion.Security
  2. 使用后缀为类名,指示其用途如UserDTO,UserAction等。

这篇关于如果一个类具有相同的名称作为命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆