如何选择最合适的设计模式

发布于 2024-11-09 07:46:37 字数 144 浏览 3 评论 0原文

我有一个问题如下。

我们开始在我们的信息亭接受公司卡,公司卡授权算法/例程将因公司而异。我们希望有一个适当的设计,当一家公司向我们提出他们的算法/例程时,它将帮助我们以最少的编码向现有系统添加新的算法/例程。

预先感谢,

乔。

I have a problem which is as follows.

We are starting to accept corporate cards in our Kiosks, The corporate cards authorization algorithm/routines will be different for companies. We would like to have a design in place which will help us to add a new algorithm/routines to the existing system with minimum coding whenever a company approaches us with their algorithm/routines.

Thanks in advance,

Joe.

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

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

发布评论

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

评论(4

凶凌 2024-11-16 07:46:37

看一下 策略设计模式

我猜这将是最接近您正在尝试的实现!

您将需要一个带有标准方法的 CardStrategyBase 类来处理这项工作。
然后,Card1Strategy 类、Card2Strategy 类等将具有特定于每种卡类型的实际算法实现。所有卡片类型共有的所有内容都可以放入 CardStrategyBase 类中。

Take a look at the Strategy design pattern

Guess this would be the closest to what you are trying to achieve!

You will need a CardStrategyBase class with standard methods to handle the work.
Then, Card1Strategy class, Card2Strategy class,... etc. Will have the actual algorithm implementation specific to each card type. All stuff common to all card types can go into the CardStrategyBase class.

Saygoodbye 2024-11-16 07:46:37

正如其他人所说,策略模式非常适合这种情况。

当您的实体(公司)的行为(授权)不同时,封装该行为并将其与实体的定义分开。

As other folks said, Strategy Pattern suits this scenario very well.

When your entities (Companies) differ in behavior(Authorization), encapsulate the behavior and make it separate from the entities' definition.

惯饮孤独 2024-11-16 07:46:37

您可以使用策略模式 http://sourcemaking.com/design_patterns/strategy 这对您的工作有很好的参考

You may use Strategy Pattern http://sourcemaking.com/design_patterns/strategy this is good reference for your work

梦明 2024-11-16 07:46:37

依赖倒置(DI)。

策略模式的“问题”在于,虽然它允许您从可用实现列表中进行选择,但它并没有解决为新卡添加新实现的问题。

一般来说,大多数不错的 DI 实现都允许您在无需进行重大部署的情况下添加新的实现;之后,可能只需添加适当的配置即可启用新的实现。

Dependency Inversion (DI).

The "problem" with the strategy pattern is that it while it let's you pick from a list of available implementations it doesn't address adding new implementations for new cards.

Generally speaking, most decent DI implementations allow you to drop new implementations in without having to do a major deployment; after which it might only be a matter of adding appropriate configuration to enable the new implementation(s).

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