Java代码管理 [英] Code Management in Java

查看:81
本文介绍了Java代码管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我来自Java背景.很明显,我已经习惯了打包的概念和文件名与文件的强关联. Java中的类名称.我关心的是-如何在.NET中实现Java包的这种含义?

例如,在com.satyam.contactManger.domain包中用Java创建类Person,
我们将首先创建包,然后在其中创建Person 类.
类似于创建另一个类,例如Address,我们将重复相同的过程.

但是在.NET中,很难按照层次结构来维护这样的代码组织. namespace 存在,但我认为这不足以维持代码的组织和层次结构.有什么好的方法可以解决此问题?

请发送有关代码组织的一些有用建议.

在此先感谢
-Satya182

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

推荐答案

谢天谢地,.NET开发人员避免了对模块和包装的Java概念的误解!

首先,C#源代码文件结构与代码无关.本质上,编译后会完全忘记文件/目录名称.对于F#等其他语言,编译顺序至关重要,文件结构必须简单明了.并且编译顺序保留在项目结构中(VS提供"up"和"down"命令).

其次,您可以使用名称空间(强烈建议使用).同样,名称空间不影响任何功能,范围或数据可见性,可以任意选择.即使在自动生成某些代码时建议使用命名空间的某些命名规则(与Java中的目录结构基本类似),该名称也与文件/目录名称无关,并且可以不同.

.NET的模块化,打包和部署的概念基于程序集和模块的概念(但是Visual Studio不支持创建多模块程序集,因此通常人们使用以下模式:一个模块中有一个程序集,一个可执行文件中有一个程序集" ").装配不同的装配所需的所有信息都全面包含在装配元数据中;因此不再需要其他信息(不需要包含文件或其他我们过去都学过的愚蠢方法).您肯定需要阅读Microsoft帮助中有关.NET编程的介绍性页面,以了解程序集的概念及其开发和使用.这很容易.

就是说,由于拥有.NET模块化的所有自由,您可以将任何规则应用于您可能会喜欢的项目结构和名称空间,包括Java.
所以...很高兴!

通常,在更改编程语言和编程技术时,不建议模拟您喜欢并经历过的另一种语言的功能.取而代之的是,您需要不加全神贯注地理解新语言/新技术的思想,扩展您的思维,然后批判性地看待两种语言,并尝试使用批判性思维来获得最佳的一切.这是我对你的最大祝愿.

谢谢,祝你好运.
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.


这篇关于Java代码管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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