架构:在开发/生产中使用不同的类

发布于 2024-08-11 11:54:12 字数 184 浏览 3 评论 0原文

我对在 2 个不同的环境中使用 2 个不同的类感兴趣。两个类应共享相同的结构(方法),但生产中使用的结构将是“轻量级”,验证较少或功能较少或操作不同。

示例:一个不检查字段类型/是否存在的 SQL 查询类。 其他示例:记录消息但不显示消息的错误处理类。

我认为已经存在一种特定的设计模式,但我真的不知道应该深入研究哪一种。

I'm interested about using 2 different classes in 2 different environment. Both classes should share the same structure (methods), but the one used in production would be "light", with less verifications or less funtionnality or different actions.

Example: a SQL query class which doesn't check the type/existence of fields.
Other example: a error handling class who logs and doesn't display messages.

I presume a specific design pattern already exists, but I don't really know which one I should digg into.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

丘比特射中我 2024-08-18 11:54:12

这可能只是我……但这真是个坏主意。

您不应该让未在开发/测试中运行的代码实时运行。否则,无法验证代码是否正常工作(当然,除了将其推入生产环境并祈祷之外)。

因此,我认为您不会找到您正在寻找的内容的好例子。

更新

您所描述的内容与您原来问题的内容略有不同。如果是这种情况,您可以让“框架”读取指定验证和日志记录级别的配置文件。这样,您的配置文件可以在不同环境之间有所不同,但仍然运行相同的代码库。

This may just be me...but that's a really bad idea.

You shouldn't have code running in live that you're not running in Development/Test. Otherwise, there's no way to verify that the code is working properly (other than, of course, pushing it in to production and crossing your fingers).

For that reason, I don't think you're going to find a good example of what you're looking for.

Update

What you described is slightly different than how your original question reads. If that's the case, you can have your 'framework' read for a configuration file that specifies validation and logging levels. That way, your configuration file can differ between environments and still be running the same code base.

盗梦空间 2024-08-18 11:54:12

同意上面关于不在生产环境和开发环境中运行不同代码的大多数评论。

也就是说,您可能正在寻找 Factory工厂方法模式。

Agreed with most of the comments above with respect to not running different code in production vs. development environments.

That said, you're probably looking for a Factory or Factory Method pattern.

知你几分 2024-08-18 11:54:12

就我而言,我有一个带有沙箱和实时环境的支付网关。我所做的是使用 工厂 模式+接口(因此所有网关都具有相同的签名)+配置(系统知道需要实例化什么类)

In my case I have a payment gateway with a sandbox and live environment. what I did was to use a factory pattern + Interfaces (so all gateways have the same signature) + configuration (where the system knows what class need to instance)

深海蓝天 2024-08-18 11:54:12

在不同的环境中使用不同的代码并不是一个好主意。

对于您的场景,我认为最好的选择是将您想要在特定环境中避免的事情外部化为配置方面,并且在部署应用程序时设置详细的日志开/关、字段的健全性检查开/关等。

任何更改必须以一致的方式对环境进行保护,以避免出现问题。版本控制系统以及一致的构建和部署过程是您的朋友。

Is not a good idea to have different code in your different environments.

For your scenario, I think the best option is to externalize as configuration aspects the things you want to avoid in a particular environment and when the application is deployed set detailed logs on/off, sanity check of fields on/off, etc.

Any changes to the environments must be done in a consistent manner to avoid problems. A version control system and a consistent build and deploy process are your friends for that.

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