Connascence – Identify Coupling

Connascence  – a tool to identify components coupling. A guide towards refactoring to better code, low coupled and easy to change.

Connascence is a software quality metric invented by Meilir Page-Jones to allow reasoning about the complexity caused by dependency relationships in object-oriented design much like coupling did for structured design. In software engineering, two components are connascent if a change in one would require the other to be modified in order to maintain the overall correctness of the system.

wikipedia

However, I am not writing to describe the history or journey of Connascence. If you are new to this term, please check the Wikipedia or references I have added at the end of this post.

Moreover, I am creating a short summary of different types of Connascence so that I can remind myself in the future. Please feel free to correct me if anything here I mentioned is not correct

Strength

The list above is sort by Strength. Name is the weakest and Identity is the strongest coupling. The weaker is the better

Locality

To be precise, we cannot get rid of coupling in our software, and we must have some dependencies among components. Connascence is a metric of identifying the part of your code that requires refactoring. If any of these couplings is inside the same class is better than spreading across multiple classes. So, Locality matters when analyzing connascence.

Degree

The number of occurrences is also important when considering Connascence. I reckon up to two occurrences are acceptable, and the third appearance should move towards refactoring. And this is Degree of connascence

My observations

  1. Careful about playing with object’s references (CoI) and Timing (CoT)
  2. Few connascence types tell us when duplicate code smells. Values (CoV), Algorithm(CoA), Meaning (CoM) detect duplicate code
  3. Try to reduce the dependency of two kinds of orders, Execution (CoE) and Position (CoP)
  4. Reduce the use of primitive types (CoT)
  5. A component should know about the Name of other components as less as possible (CoN)

Helpful Links

Finally, some helpful resources enlightened me about Connascence.

I would like to hear your thoughts