I have a problem how to go about naming my namespaces and classes. I already figured they shouldn't both have the same name, as it causes all kinds of problems. Most notable problem for me is that I need to fully qualify the class or make an alias. Here is what I have:
Model.DataSource.DataSource
Model.DataSource.FileSystemDataSource
Model.DataSource.JsonDataSource
Model.DataSource.XmlDataSource
Model.DataSource.DataSourceConstraints
Model.DataSource.DataSourceStorage
Model.DataSource.DataTable
... // more others
Model.QueryStorage.QueryStorage
Model.QueryStorage.FileSystemQueryStorage
... // more others
Model.Project.Project
Model.Project.ProjectFactory
As you can see, I have 3 classes that are named same as packages they are in. Two of them are interfaces so I could consider prefixing them with I
but I really don't like this convention. I also heared the proposition to name package like ProjectUtils
or something. But I think these are not utils, they are legit domain objects. I could alias, with using
but what is a better name for Project
than Project
?
I can't figure out a way to have sensible names for my classes without duplicates.
MyClass : Foo, Bar
actually compiles, sinceFoo
andBar
could both be classes, or interfaces? Even if you don't care for it, remember to write code as if the next guy maintaining it is a maniac with an axe, who knows where you live...Foo extends Bar implements Baz
whereBar
can be interface or class, and same forBaz
and noone needs anI
. You usually know why and what you want to implement/inherit from and why you are doing it.I
or not is not important. The primary audience of your code is other developers and so you have a duty to make your code easy to read. That means following the conventions of the language. So when writing Java, don't use theI
; when writing C#, you should use it.