English subtitles

← Coupling Between Classes - Intro to Java Programming

Get Embed Code
4 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. Let me tell you about a useful concept that you can use to organize your
  2. classes effectively. It's called the concept of coupling. And we'll say that a
  3. class is coupled with another if it uses the other class. In fact,
  5. shows us this relationship, with these arrows that you may have noticed before.
  6. In this example, the Car class. Is coupled with a Person class, because the
  7. code of the Car class uses personal objects. But the Person class is not
  8. coupled with the Car class because the personal object actually knows nothing
  9. about cars. Let me show you. When you look at the code of the Person class
  10. you'll see there are no cars inside, but when you look at the code for the Car
  11. class, there's a person here, and a Person class is used up here. Like I said,
  12. the Car class knows about the Person class, but the Person class doesn't know
  13. about the Car class. It's a good idea if not every class knows about every
  14. other, it makes it easier to make changes. For example, if we make a change in
  15. the Car class, the Person class doesn't care. It never knew the class in the
  16. first place. One wants to keep the coupling between classes as low as possible.
  17. Let's see what other classes the Car class might be coupled with. Go ahead, go
  18. through the code of the Car class, and give me a list of all of the classes
  19. that the Car class uses. Just put the names of the classes into this box.