DEV Community

loading...
Cover image for Code Smell 08 - Long Chains Of Collaborations

Code Smell 08 - Long Chains Of Collaborations

mcsee profile image Maxi Contieri Originally published at maximilianocontieri.com Updated on ・1 min read

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

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.

Credits

Photo by Chewy on Unsplash

Discussion (0)

pic
Editor guide