.net - NET: Best Practices/guidelines for dividing namespaces between files? -


What should be the general guidelines / gaucheas for splitting the application code (APCDD) into separate files?

I have found that, over time, the original files do not match well how the namespace hierarchy develops, how do I organize the application code container smoothly over time?

In what direction should the file divisions be targeted? Code portability? separation of concerns? Common functional references? Frequency of change? Do they strive for 1-1 relations with classes?

What are the implications of integrating into some files by dividing the code into some files?

I have often thought about it but have never reached any general conclusions, which apply to all situations.

The answer to this question is not absolute because it depends on the work in your hand. If you are making some types of SDK for reuse of others, the namespace is very important; However, if you are just making an in-house tool with just a few classes, the namespaces are very unimportant.

Classes

Generally, classes should have their own files, it makes it simple that people navigate around code solutions, help with development and maintenance (for example , When all change the same file then changes are very difficult to merge). In some situations, it may be acceptable to divide one class into more than one file such as:

  • When nested classes are there, each nested class can have its own file.

  • When there are auto-generated portions for a category such as designer code.

  • When there are definite parts in the class, such as a general set of hidden assets or a general implementation of the interface.

In one of our projects, we have a general implementation of the interface, which exposes many sections. As we do not have multiple heritage, we take a mixture-in approach, under which we automatically generate an additional file for each class.

There are other situations as well, but it is subjective and depends on the needs of your own project.

Namespace

Namespaces should generally focus on their kind of sensible group. A namespace should be easily found by a developer to find out what they are looking for. For many small projects, a single name space such as MyAwesomeTool is sufficient, but for a large project for a large project a more logical group would be required, such as major projects such as SDK or .NET BCL. Depends on dissolving, otherwise large-scale large collections of type. Additional names are provided in each namespace level, which is found there, such as System.Windows.Forms or System.Drawing or Microsoft.VisualBasic .

When creating a namespace, each idea should be given for the purpose of that namespace and associated project. If the project is in-house and small, call names that you like because it is essential for a group of your type; If the project is externally visible or there are too many types, think carefully about the rational and meaningful group, which enables others to easily find those types of types that they are looking for.

Conclusion

There are no strict rules working under all circumstances, how do you organize the files in your code, related to your own development processes, you and your team Affect; Hell will be developed to develop all of your classes in a file, but the compiled product will not do any different work (provided the method of a file does not reach the errors), while your name space system is linked to future development and consumers. Those namespaces are, therefore, the consequences of getting it wrong can be more serious.

  • The goal of organizing your classes in a manner that simplifies the current development and future maintenance.
  • Organize your namespace in a way that makes all the development easier and where appropriate, the experience of your end users.

Comments