论坛首页 编程语言技术论坛

.Net最佳实践 (11-22)

浏览 1750 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-08-31  

 

  1. Do not make the member variables public or protected. Keep them private and expose public/protected Properties. ( It is mandatory )


11. 不要设置成员变量为 公开的或者被保护的。设置他们为私有的,然后暴露 成公开的或者被保 护的属性。(强制的)

 

  1. The event handler should not contain the code to perform the required action. Rather call another method from the event handler.


12. 一个事件控制器不应该包含 代码执行要求的动作,而应该从事件控制器里面 调用另一个方法。

 

  1. Do not programmatically click a button to execute the same action you have written in the button click event. Rather, call the same method which is called by the button click event handler.


13. 不要通过程序来 点击一个按钮,来执行你已经在这个按钮点击事件里面实现了的相同的动 作。而应该调用在 按钮点击事件控制器里面调用的那个相同的方法


 

  1. Never hardcode a path or drive name in code. Get the application path programmatically and use relative path.


14. 绝对不要将路径或者驱动器名称硬编码到代码 中。用程序来获取应用程序路径或者使用相对路径。

 

  1. Never assume that your code will run from drive "C:". You may never know, some users may run it from network or from a "Z:".


15. 绝对不要假设你的代码会从 C 盘下运行。你可能从来不知道,有些用可能从网络运行它,或者从 Z 运行。

 

  1. In the application start - up, do some kind of "self - check" and ensure all required files and dependencies are available in the expected locations. Check for database connection in start up, if required. Give a friendly message to the user in case of any problems.


16. 在应用程序启动的时候,做一些 自我检测 保证 必要的文件或者依赖在期望的位置是可 用的。 如果有必要,在启动的时候检测数据库连接。如果存在任何问题,给用户一个友好的提示消息。

 

  1. If the required configuration file is not found, application should be able to create one with default values.


17. 如果找不到必要的配置文件,应用程序应该能够默认值来创建一个。

 

  1. If a wrong value found in the configuration file, application should throw an error or give a message and also should tell the user what are the correct values.


19. 如果在配置文件中发现一个错误的值,应用程序应该抛出一个错误或者给一个提示消息 ,也 应该告诉正确的值应该是什么。

 

  1. Error messages should help the user to solve the problem. Never give error messages like "Error in Application", "There is an error" etc. Instead give specific messages like "Failed to update database. Please make sure the log in id and password are correct."


19. 错误消息应该帮助用户解决问题。绝不要 给出像这样的错误消息: 应用程序错误 里有一个错误”等。应该给出像这样的明确的消息:“更新数据库失败。请确认登录编号和密码是正确的。”

 

 

  1. When displaying error messages, in addition to telling what is wrong, the message should also tell what the user should do to s olve the problem. Instead of message like "Failed to update database.” suggest what should the user do: "Failed to update database. Please make sure the login id and password are correct."


20. 显示一个错误消息的时候,除了告诉什么东西错了,提示消息应该告诉用户应该做什么来解决这个问题。取代这样的消息:“更新数据库失败。”,建议用户应该做什么:“更新数据库失败。请确认登录编号和密码是正确的。

 

  1. Show short and friendly message to the user. But log the actual error with all possible information. This will help a lot in diagnosing problems.


21. 显示简短的 友好的消息给用户。但是在日志中要记录和 实际错误相关的所有可能的信息。 这将对诊断问题起到很大的帮助

 

  1. D o not have more than one class in a single file.


22. 单个文件中不要有多个类。

 

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics