Skip to content

Commit

Permalink
Fic hint and error messages for the strategy task
Browse files Browse the repository at this point in the history
  • Loading branch information
onewhl committed Nov 9, 2023
1 parent 8c9ce9a commit 46e5c2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions RefactoringToDesignPatterns/StrategyPatternPractice/Task/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
This class should take as a constructor parameter `paymentStrategy: PaymentStrategy`
and should contain the `processOrderPayment` method, which invokes the `processPayment` method from `paymentStrategy`.
- Transform the `Order` class into a `data class` that encapsulates details regarding the order's price and date.
- Within the `Main::main` method, for every payment type, instantiate a `PaymentProcessor`. Ensure you pass the
corresponding payment strategy during the object's creation.
- Within the `Main::main` method, instantiate an `Order` object for each order and a `PaymentProcessor` for each payment type.
Make sure to pass the corresponding payment strategy when creating the `PaymentProcessor` object.

By using the **Strategy** design pattern, the payment processing logic is separated from the `Order` class,
making it more flexible and maintainable.
Expand Down Expand Up @@ -52,13 +52,15 @@ class CreditCardPayment : PaymentStrategy {

<div class="hint" title="How to fix main method?">

In the main method, you should instantiate a `PaymentProcessor` object and provide the appropriate payment strategy as
an
argument. For instance, for a credit card payment type, the code would be:
In the main method, **for each order**, you should instantiate an `Order` object, providing it with the corresponding total amount and date.
Then, you need to instantiate a `PaymentProcessor` object, supplying it with the appropriate payment strategy as an argument.
Finally, you should invoke the `processOrderPayment()` method.
For example, the code for processing a payment with a credit card would be:

```kotlin
val order1 = Order(100.0, LocalDate.of(2023, 3, 1))
val creditCardPayment = PaymentProcessor(CreditCardPayment())
creditCardPayment.processOrderPayment(100.0)
creditCardPayment.processOrderPayment(order1.totalAmount)
```

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ class StrategyPatternTest : BaseIjTestClass() {
findMethodUsages(method),
listOf("main")
) {
"Please, invoke the $method method of Credit Card Payment in the main method"
"Please, invoke the $method method of Credit Card Payment and pass in the totalAmount from the first order within the main method"
}
method = "processOrderPayment(order2.totalAmount)"
Assertions.assertEquals(
findMethodUsages(method),
listOf("main")
) {
"Please, invoke the $method method of PayPal Payment in the main method"
"Please, invoke the $method method of PayPal Payment and pass in the totalAmount from the second order within the main method"
}
method = "processOrderPayment(order3.totalAmount)"
Assertions.assertEquals(
findMethodUsages(method),
listOf("main")
) {
"Please, invoke the $method method of Bitcoin Payment in the main method"
"Please, invoke the $method method of Bitcoin Payment and pass in the totalAmount from the third order within the main method"
}
}
}

0 comments on commit 46e5c2a

Please sign in to comment.