From the course: Spring: Design Patterns

Unlock the full course today

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

Adapter pattern in action

Adapter pattern in action

From the course: Spring: Design Patterns

Start my 1-month free trial

Adapter pattern in action

- So now that we have discussed the adaptor pattern and what its used for and how it operates, it's time to go implement it in code. I would like you to go ahead and navigate to your IDE. and open our source, main, java, our base package and lets create a new package in here called adapter. Now we are going to create an adapter that is going to treat an orange like an apple. Which is something Gus Porticolis would very happy with us, since apples and oranges are all fruit. So let's start with an interface for apple. Our apple interface is going to implement two methods. One is going to be a getVariety and another is going to void method called eat. So now that we have built the apple interface, let's go create our orange interface. Now, our orange interface is going to look very similar to our apple but it's going to have getVariety string method and it's also going to have a void eat method but its going to have a void peel method and a void juice method. And that is all we are going…

Contents