Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

I'm from Java Background. And obviously, I'm quite used to the concept of package and strong association of file name & Class name in Java. My concern is - How to implement such meaning of package of Java in .NET?

For example to create a class Person in Java in com.satyam.contactManger.domain package,
we would firstly create the package and then create the Person class in it.
similarly to create another class let's say Address, we would repeat the same process.

But in .NET, it's hard to maintain such organization of code in terms of hierarchy. namespace is there, but I think it's not enough to maintain the code organization and the hierarchy. Is there any good way to resolve this issue?

Please do sent in some useful suggestion for code organization.

Thanking in Advance
-Satya182
Posted

1 solution

Thanks goodness, developers of .NET avoided that ill-conceived Java concept of modularity and packaging!

First, C# source code file structure has nothing to do with the code. Essentially, file/directory names are completely forgotten after compilation. With some other languages like F#, order of compilation is essential, the file structure must be plain; and order of compilation is preserved in the project structure (VS provides "up" and "down" commands).

Secondly, you can use name spaces (highly recommended). Again, name spaces do not effect any functionality, scope or data visibility and can be chosen arbitrarily. Even though certain naming rules for name spaces is suggested when some code is auto-generated (following directory structure pretty much as in Java), this name have nothing to do with file/directory names and allowed to be different.

The concepts of modularity, packaging and deployment of .NET is based on the concept of Assembly and Module (but Visual Studio does not support creation of multi-module assembly, so usually people use the schema "one assembly in one module and one executable file"). All the information needed to like different assemblies is comprehensively contained in assembly meta-data; so no other information is ever needed (no include files or other stupid approaches we all learned in the past). You will certainly need to read introductory pages from Microsoft help on .NET programming to catch the concepts of Assemblies and their development and usage; and this is quite easy.

That said, with all the freedom of .NET modularity, you can apply any discipline for project structure and name spaces you may feel comfortable with, including that of Java.
So... rejoice!

Usually, when changing programming language and programming technology, it is not recommended to simulate features of another language you like and experienced with. Instead, one needs to try to understand the ideas of new language/technology without any preoccupation, expand your mind and then look critically at both languages and try to get the best of all, using your critical thinking. This is my best wish for you.

Thank you and good luck.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 24-Dec-10 18:29pm    
Impressive argumentation! 5+
Espen Harlinn 26-Feb-11 11:05am    
Good reply - a 5
Sergey Alexandrovich Kryukov 26-Feb-11 19:29pm    
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900