多个提供商/供应商的典型模式?
我正在构建一个软件产品,客户将能够将其系统配置为使用 3 或 4 个预集成支付网关供应商中的任何一个。 (例如:PayPal、Authorize.net 等)。
客户将登录应用程序,导航至设置,选择他们拥有帐户的供应商,输入相关帐户信息并保存。然后,处理的支付交易将通过特定的支付网关供应商 API。
我正在寻找一种模式来将其从支付的实际功能中抽象出来。也就是说,当用户进行支付时,会实例化一个 Payment 对象,然后调用 Payment->validate(),然后调用 Payment->save()。我希望这个 Payment 类抽象出后端将使用哪个特定供应商的详细信息。
因此,此 Payment 类需要能够确定已配置的支付网关供应商(已完成,无需寻求帮助),然后实例化该特定支付网关类的对象,并调用相关方法。
所以我要问的是,这种类型的东西是否有一个典型的设计模式,它叫什么,以及您是否有关于这方面的好材料的链接。我不是在寻找“帮我写这段代码”类型的信息,我正在寻找“授人以鱼”类型的信息:-)
谢谢。
I'm building a software product, in which the customer will be able to configure their system to use any one of 3 or 4 pre-integrated payment gateway vendors. (eg: PayPal, Authorize.net, etc).
The customer will log into the application, navigate to settings, select which vendor they have an account with, enter the relevant account information and save. Then, and payment transactions processed will go through that particular payment gateway vendor API.
I'm looking for a pattern to use to abstract this away from the actual function of making a payment. That is, when a user makes a payment, a Payment object is instantiated, then Payment->validate() is called, then Payment->save() is called. I want this Payment class to abstract away the details of which particular vendor will be used on the backend.
So this Payment class will need to be able to determine the configured payment gateway vendor (done, not asking for help with that), then instantiate an object of that particular payment gateway class, and call relevant methods.
So what I'm asking is, is there a typical design pattern for this type of thing, what is it called, and do you have links to good material on this. I'm not looking for "help me write this code" type of information, I'm looking for "teach a man to fish" type of information :-)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用 GoF 书中的策略模式。您编写一个提供 validate( payment ) 和 save( payment ) 的 AbstractPaymentService ,而不是 Payment-> save() 。然后,对于每种支付服务类型,您可以实现 AbstractPaymentService(例如 PaypalPaymentService)。
I would use the Strategy Pattern from GoF book. Instead of Payment->save() you write an AbstractPaymentService that provides the validate(payment) and save(payment). For each payment service type you then implement the AbstractPaymentService (e.g. PaypalPaymentService).