脚本宝典收集整理的这篇文章主要介绍了php适配器模式(adapter pattern),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
下午陪家人和小孩,晚上练起来。
<?PHP /* The adapter pattern allows the interface of an existing class to be used From another interface,basically,helping two incompatible interfaces to work together by converting the interface of one class into an interface expected by another class. */ class StriPE { public function capturePayment($amount) { echo $amount . " Stripe_capturePayment<br/>"; } public function authorizeOnlyPayment($amount) { echo $amount . " Stripe_authorizeOnlyPayment<br/>"; } public function cancelAmount($amount) { echo $amount . " Stripe_cancelAmount<br/>"; } } interface PaymentService { public function capture($amount); public function authorize($amount); public function cancel($amount); } class StripePaymentServiceAdapter implements PaymentService { PRivate $stripe; public function __construct(Stripe $stripe) { $this->stripe = $stripe; } public function capture($amount) { $this->stripe->capturePayment($amount); } public function authorize($amount){ $this->stripe->authorizeOnlyPayment($amount); } public function cancel($amount) { $this->stripe->cancelAmount($amount); } } $stripe = new StripePaymentServiceAdapter(new Stripe()); $stripe->authorize(49.99); $stripe->capture(19.99); $stripe->cancel(9.99); ?>
以上是脚本宝典为你收集整理的php适配器模式(adapter pattern)全部内容,希望文章能够帮你解决php适配器模式(adapter pattern)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。