From the course: Java Design Patterns: Behavioral Part 2

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Solution: The Strategy pattern

Solution: The Strategy pattern - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 2

Start my 1-month free trial

Solution: The Strategy pattern

(upbeat music) - [Instructor] Now let's have a look at my solution to this exercise. Yours might look a bit different to mine, which is totally fine. So, I've created a new interface called account. And this defines a method called, make payments, which takes an int called amount, as an argument. I then have two more methods in here, for each type of accounts. So the first is called bank accounts, and this prints out the message saying that's a payments of X amount, has been made from a bank account, below this, I have a similar method called PayPal accounts. I can see that it's very similar, but at the message says that the payments has been made from a PayPal account instead of a bank account. So, now, if I go back to my customer class, I've only got a single method in here called, make payments, and I'm passing in an account and an amount. Then I'm calling the make payment method on the account object, and passing in…

Contents