何时使用显式字符串或常量字符串

发布于 2024-09-30 03:48:31 字数 317 浏览 0 评论 0原文

就字符串而言,我理解需要让字符串重用包装在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

战皆罪 2024-10-07 03:48:31

当您需要能够更改功能而无需重新部署/重新编译时,请使用配置。

如果您的字符串在应用程序中重复使用,但所涉及的功能不是您想要可配置的,请使用常量。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文