Created
August 22, 2016 13:32
-
-
Save dborovikov/e049a23febc52511e0b599ab4073da6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Payments { | |
| trait PaymentProcessorType { | |
| } | |
| object DefaultPaymentProcessorType extends PaymentProcessorType | |
| trait PaymentProcessor { | |
| def processorType: PaymentProcessorType | |
| def process(payment: Payment): Unit | |
| } | |
| class DefaultPaymentProcessor extends PaymentProcessor { | |
| def processorType: PaymentProcessorType = DefaultPaymentProcessorType | |
| def process(payment: Payment): Unit = ??? | |
| } | |
| case class Payment(paymentProcessorType: PaymentProcessorType) | |
| def processPayment(p: Payment): Unit = { | |
| val processor = p.paymentProcessorType match { | |
| case DefaultPaymentProcessorType => new DefaultPaymentProcessor | |
| } | |
| assert(processor.processorType == p.paymentProcessorType) | |
| processor.process(p) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment