如何避免一类具有相同的名称和它的命名空间,如Technology.Technology? [英] How to avoid having the same name for a class and it's namespace, such as Technology.Technology?

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

问题描述

我经常有该命名空间内的命名空间和类之间的命名冲突,并想知道处理这个最佳实践时,它似乎是有道理首先使用这些名字,除了添加随机prefixes。

I am frequently having naming conflicts between a namespace and a class within that namespace and would like to know a best practice for handling this when it seems to make sense to use these names in the first place, besides adding random prefixes.

这似乎有道理有Models.Technology命名空间,与数十家技术类(即武器,农业,循环利用技术),并在它的一些相关的接口。我也决定有技术抽象类,在空间技术,使所有技术派生。

It seemed to make sense to have a Models.Technology namespace, with dozens of technology classes (ie. Weapon, Agricultural, Recycling technologies) and some related interfaces in it. I also decided to have a Technology abstract class, in the Technology namespace, from which all technologies derive.

不过,这迫使我使用code是这样的:

However, this is forcing me to use code like this:

public Technology.Technology research(Technology.Technology tech) {...}

和同样:

public Building.Building build(int count) {...}

顺便说一句,因为我用这个词在其他地方的包装可用的技术清单...

By the way I did not name my namespace Technologies since I use that term elsewhere as a wrapper for a list of available technologies...

推荐答案

如果没有更多的precise迹象给你一些一般性的建议。

Without more precise indications on when you encounter this problem it's hard to give you some general advice.

但我会想,当你在你的命名空间的基类,你有这个问题,与其他类从中继承。如果是这样的话,你可以打电话给你的类BaseTechnology(基类)或AbstractBuilding(抽象类)或IAnimal(接口)。这甚至让你更清楚,因为你在你的类型,一些重要的东西关于它的名称来指定。

But I'm gonna suppose you have this problem when you have a base class in your namespace, with others classes inheriting from it. If that's the case you could call your class BaseTechnology (base class) or AbstractBuilding (abstract class) or IAnimal (interface). This even give you more clarity since you specify in the name of your type something important about it.

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

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