Unityで処理を別ファイルにしようとしていて、namespaceとクラス名をどういうふうにつけようか考えているなか、同じ名前にしようかと思った。
調べているうちに以下を見つけた。
Do not name a class the same as its namespace, Part One
namespace MyContainers.List
{
public class List { … }
}
上記がまずい理由として以下の理由があげられている
Part One: Collisions amongst referenced assemblies:
以下の実装において、Fooを参照しようとして、どのFoo?となってしまうとのこと。
// Foo.DLL:
namespace Foo { public class Foo { } }
// Bar.DLL:
namespace Bar { public class Foo { } }
// Blah.DLL:
namespace Blah
{
using Foo;
using Bar;
class C { Foo foo; }
}
回避策は上記リンクであるようだが、結局は「最初からFoo.DLLの著者がguidelinesに基づき、かつ、typeとnamespaceを同じようにしないことで避けられる」とのこと。
The problem can be avoided in the first place by the authors of Foo.DLL following the guidelines and not naming their type and their namespace the same thing.
using Fooとusing Barを同時にするのをやめてFoo::Foo, Bar::Fooという書き方にするのはどうなのだろうか?
このあたりはどういうのが標準的かまだ良くわかっていない。