Method cohesion

Image credit: https://www.slideshare.net/agileee/lightening-talk-software-craftsmanship

The Method exhibits high cohesion when a method performs one and only one operation and do what their names say they do.

If they do anything else, they are less cohesive and poorly named.

Examples of highly cohesive methods:

  • GetProductName()
  • PrintBarcode()
  • ToLower()
  • CalculateAge()
  • CreateUser().

3 responses to “Method cohesion”

  1. […] see the refactored version of the above long method. It is divided into small, cohesive, fine-grained methods which are doing one and only one […]

  2. […] long method does more than one thing and it is not cohesive. The method more than 10 lines could be considered as long […]

  3. […] function should be cohesive. The function should say what you mean. The consumer of the function should not browse your […]

Leave a Reply

I’m Datta

Welcome to BeingCraftsman — where software architecture is treated as a long-term responsibility. I’m a Software Architect and Cloud Lead based in Pune, India, with over a decade of experience designing scalable systems, guiding teams, and making practical engineering decisions. This space is about clarity in architecture, reliability in systems, and leadership that helps teams build software that lasts.

Let’s connect

Linkedin

Discover more from Being Software Craftsman (DFTBA)

Subscribe now to keep reading and get access to the full archive.

Continue reading