Loose Coupling

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Any engineering task of any kind of complexity (except the most trivial) requires that the problem be broken up into smaller problems. (See Breaking Up the Problem.)

When you have two solutions to two different problems and you want to combine them to solve a larger problem, then you have to couple the solutions.

There are two ways to do this.

One way requires a million tiny little things all to match and marry in exactly the right way. Think of brain surgery. If you were to do a brain transplant, you would have to make billions of connections, and they have to be connected in exactly the right way. This is why brain transplants are impossible. However, other organs can be transplanted because they have loose coupling with the rest of the body. For instance, the heart pretty much pumps blood and that's it. A really, really good example of loose coupling is the power plug on your electric devices. Two prongs that you stick in a socket, that's it. Another good example is automobile carburetors. Did you know that you can actually put the same carburetor on different kinds of engines made by different companies?

When you write your software, minimize the required coupling. Here are the things you want to limit:

  • The environment variables or configuration file requirements.
  • The number of things possible to do.
  • The number of parameters to each of those things.
  • The UI of the component.

Limit those things, and you'll find that it's easier to integrate your components. Not only that, but you'll find the components are reusable in ways you couldn't anticipate.