Class.Class VS Namespace.Class的顶级通用类库? [英] Class.Class vs Namespace.Class for top level general use class libraries?

查看:194
本文介绍了Class.Class VS Namespace.Class的顶级通用类库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个更可接受的(最佳实践):

Which one is more acceptable (best-practice)?:

namespace NP
   public static class IO
   public static class Xml
   ...
   // extension methods

using NP;

IO.GetAvailableResources ();

VS

public static class NP
   public static class IO
   public static class Xml
   ...
   // extension methods

NP.IO.GetAvailableResources ();

也为 2 中,code尺寸是通过让部分类管理,以便每个嵌套类可以是一个单独的文件,相同的扩展方法(除没有嵌套类为他们)

Also for #2, the code size is managed by having partial classes so each nested class can be in a separate file, same for extension methods (except that there is no nested class for them)

我preFER 2 ,为一对夫妇的原因,喜欢的是可以使用已经普遍使用,如 IO类型名称,我不希望更换或碰撞。

I prefer #2, for a couple of reasons like being able to use type names that are already commonly used, like IO, that I don't want to replace or collide.

哪一个你preFER?任何优点和缺点每个?什么是这种情况的最佳做法是什么?

Which one do you prefer? Any pros and cons for each? What's the best practice for this case?

编辑:也会有两者之间的性能差异

Also would there be a performance difference between the two?

推荐答案

我想说的#1。因为当你捆绑了大量的类到一个静态类,你做同样的事情作为一个命名空间是换货的。这就是为什么我会说这是最好的让命名空间为你做的。

I would say #1. Because when you bundle up lots of classes into one static class you do the same thing as a namespace is ment for. Which is why I would say it is best to let namespaces do that for you.

在这种情况下,你也可以摆脱其用在你想加入的情况下写的NP眼前的一切的。我觉得就应该把你的巢命名空间,使他们不会相撞我们使用更多的描述比IO命名空间的名称。

In that case you can also get rid of having to write "NP" in front of everything by adding using in case you want. I think you should either nest your namespaces so that they wont collide our use more describing namespace names than IO.

大多数时候,最好的做法是微软做的,我从来没有见过他们做的#2

Most often the best practice is what Microsoft do and I have never seen them do #2

这篇关于Class.Class VS Namespace.Class的顶级通用类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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