Software Quality measurement metric : Connascence

2022.09.26

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Development of a large software involves a large number of modules, and these modules are dependent on each other. Earlier, when the concept of connected modules was new to the field of software engineering, we were all introduced to the term coupling which determined the degree of independence between software modules. While this term is still being used, it was specifically defined for structured programming languages, right now object oriented languages are all the trend.

The recasted term for coupling for Object Oriented Design is connascence, it was first defined by Meiler Page-Jones in the following words:

Two components are consequent if a change in one would require the other to be modified in order to maintain the overall correctness of the system.

There are 2 types of connascence: static and dynamic

Static Connascence

This refers to connascence which is visible or understandable from the code which the developer has come up with. You will understand this further when you read about the types of static connascence:

  • Connascence of Name (CoN) : Multiple components must agree on the name of an entity. For example, with an object which is being referred to by multiple methods, all of these methods must refer to each of the entities of this object with the names which are present in the object’s definition.
  • Connascence of Type (CoT) : Multiple components must agree with the type of an entity. Just like methods must agree with the name of an entity, they must also agree on the type of the entity. 
  • Connascence of Meaning (CoM) : Components must agree on the meaning of particular values. This means that all the components must agree on what the constants/environment variables mean and use them accordingly.
  • Connascence of Position (CoP) : Components must agree on the order of values. This is feasible when we talk about methods. When we call methods with some arguments, the order of parameters must be in accordance with the method definition, otherwise the method might return an unexpected output or worse.
  • Connascence of Algorithm (CoA) : Components must agree on the algorithm which is being used. Let’s consider an encryption algorithm being used for transmission of some data over the internet. Until and unless both the sender and receiver are vary of the algorithm which is being used, the receiver may not understand the data which it is receiving.

Dynamic Connascence

Dynamic Connascence analyses calls at runtime. This can be understood only when the flow of a particular piece of code is understood, hence the name. Just like static connascence, dynamic connascence has been divided into multiple types which makes its understanding relatively easier.

  • Connascence of Execution (CoE) : The order of execution of multiple components is important. Let us consider an example where you want to send an HTTP request to an API endpoint, with the API defining that the request needs to have some custom headers, in which case, the headers must be defined before the request is sent and not after. 
  • Connascence of Timing (CoT) : The timing of execution of multiple components is important. Let’s say you execute an update operation and a read operation on the same data, whether you see the updated data or old data depends on which process’s thread won the race condition and finished execution first.
  • Connascence of Values (CoV) : Occurs when several values relate to one another and must change together. Let’s consider 4 points on the 2 dimensional Euclidean plane, these points are programmed to define a rectangle, if someone is to modify one point, the rest 3 must modify automatically in accordance with the initial modification to satisfy the condition that they define a rectangle.
  • Connascence of Identity (CoI) : Occurs when several values relate on one another and must change together. When 2 independent components are working on a single data structure and they must share and update it together, such as a distributed queue. 

You might have noticed that some of the types of Dynamic Connascence are vaguely defined and are difficult to understand, that is because they are. Since we lack tools to analyse runtime calls as effectively as we analyse the call graph.

Resources

connascence.io