何时使用显式字符串或常量字符串
就字符串而言,我理解需要让字符串重用包装在 XML 文件或配置节中某处的字符串(例如公司名称)中的 overname。
我遇到的问题是在哪里划清使用配置或本地表达字符串的界限?
是什么决定了是将字符串内容包装在配置文件中还是仅将字符串分配到那里然后再分配到方法中?
公司品牌网站在哪里,那么是的,我将把任何公司方面的字符串放入配置文件中。其他方面(例如文件位置等)也将包含在配置文件中。
然而,当我这样做时,我发现自己正在与其他人讨论,而不是在方法中定义显式字符串。
您是否有某些标准来定义何时使用配置部分中的字符串而不是在方法中显式定义?
In terms of strings I understand the need to have strings am going to reuse overname wrapped away somewhere in an XML file or configuration section for strings such as Company Name.
The problem am having with this is where to draw the line on using configuratioh or locally expressed strings?
What decides whether to have the string content wrapped away in a configuration file or to just have the string assigned there and then in a method?
Where am corporate branding a site then yes any corporate aspect strings I will put in a configuration file. Other aspects such as file locations etc will also go in a configuration file.
However, I have found myself discussing with others when I do this as oppose to having an explicit string defined within a method.
Do you have certain criteria that define when to use strings from a configuration section as opposed to being explicitly defined in a method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您需要能够更改功能而无需重新部署/重新编译时,请使用配置。
如果您的字符串在应用程序中重复使用,但所涉及的功能不是您想要可配置的,请使用常量。
Use configuration when you need to be able to change functionality without redeploying/recompiling.
If your string is reused within your application but the functionality involved is not something you want to be configurable, use a constant.