From the course: Java Design Patterns: Behavioral Part 1

Unlock the full course today

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

Avoiding tight coupling between objects

Avoiding tight coupling between objects - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Avoiding tight coupling between objects

- [Instructor] In this example, I have an app from E-commerce site that's used for buying and selling objects. The objects are tightly coupled. And I want to restructure it to make it more maintainable. If I have a look at the main class, which has a main method, I can see I'm creating a customer object, and then passing in an address for the customer. Then I'm calling the buy method on the customer, and passing in the item they want to buy and the amount. So in this case, the customer wants to buy three pens. If I run the app, it prints out a message to the console, saying that three pens are out for delivery to one, two, three Sunny Streets. This looks like a fairly straightforward up. But let's have a closer look at the structure and see if it's anywhere it can be improved. So let's start with this customer class. If I open it up, I can see it has two fields, a string called address and an E-commerce site, called site.…

Contents