Question

I made some research to better understand the concept of functional cohesion. Myers in his book "Composite structured design" has written about functional cohesion:

A functional-strength module is defined as a module that performs a single specific function.

He also wrote in "Reliable software through composite design" about that:

In a functional-strength module all of the elements are related to the performance of a single function.

Others authors expressed similar views:

Every essential element to a single computation is contained in the component. So functionally cohesive component is :

  • One that not only performs the task for which it was designed but
  • it performs only that function and nothing else.

or:

Functional cohesion: each part necessary for execution of a single function. e.g., compute square root or sort the array.

My question is:

  • is the single specific function in above definitions the same as "Single Responsibility Principle"?
  • or does functional cohesion mean that a java class shall have one public method only, and if there would be more public methods you wouldn’t have a functionally cohesive component?
Was it helpful?

Solution

There is a confusion between:

  • Function in its programming or mathematical sense, that is about some language constructs that can define something that can be called to achieve a result (e.g. procedure, function, subroutine,...)
  • Function in its engineering sense, meaning the purpose for which something is used.

Functional cohesion is about the latter: it’s about having a module, a package, a component that serves one specific purpose. You can for example have:

  • a string library offering a very rich set of programming functions (concatenation, search, replace) but that all serve a common purpose of working with strings. So there is a functional cohesion.
  • a utility library, with some string functions, some file management functions, some frequently used user-interface interactions, etc... Here there is no real common purpose. It’s a useful, but heteroclite collection of unrelated features without cohesion.

Of course we are working here with concepts that offer some room of interpretation and that is difficult to measure precisely.

Functional cohesion has nothing to do with the single responsibility. And single responsibility has by the way nothing to do with doing only one thing. Single responsibility is solely about reason for changes and responsibility to define the interface (see Uncle Bob’s article: he invented the concept so has some authority about what it really means)

Licensed under: CC-BY-SA with attribution
scroll top