Code Smell 08 — Long Chains Of Collaborations

Maximiliano Contieri
Dev Genius
Published in
Oct 27, 2020

--

Making long chains generate coupling and ripple effect. Any chain change breaks the code.

Photo by Chewy on Unsplash

Problems

  • Coupling
  • Break encapsulation

Solutions

  • Create intermediate methods.
  • Think about Law of Demeter.
  • Create higher level messages.

Sample Code

Wrong

Right

Detection

Automatic detection is possible using parsing trees.

Also Known as

  • Law of Demeter

Tags

  • Declarative
  • Encapsulation

Conclusion

Avoid successive message calls. Try to hide the intermediate collaborations and create new protocols.

--

--

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com