Qualities Patterns Share: Strong Cohesion

Listen to this post
Subscribe

Cohesion is a quality indicting alignment. The best way to understand and remember this is to relate the root word “cohere” to the term coherent. Lasers are often called coherent light because all the of the beams of light in a laser are perfectly aligned.

What does this mean in software? It has to do with scoping, and we focus on two version of creating scope: class scope and method scope.

Classes create their own scope. If they are strongly cohesive, then everything within the scope of a class is aligned in that all the contents of a class are about fulfilling the class’s single responsibility.

Methods create their own scope as well, but in this case the alignment is about function. All elements of a method should be aligned in that they are about performing the same, single function.

No red herrings. No 20-page methods. No grab-bag classes. Everything is focused and aligned and, therefore, coherent. All the patterns are strongly cohesive.

Getting this right can sometimes be tricky. The practices we follow can be helpful here. When we get to the practices, I’ll be able to show how following them can ensure we produce strong cohesion in design whether we use a pattern or not.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.