5

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?
4

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)

| improve this answer | |
  • thank you for answer, why doesn't the string library have informational cohesion instead of functional? ( the string library(1) contains multiple entry points (2) Each entry point performs a single specific function (3) All of the functions are related by a concept) – flexibleHammer Dec 13 '19 at 17:19
  • @flexibleHammer indeed, the string library would also have an informational cohesion, since it’s related to the same data structures. The point is that cohesion can be viewed under different angles that are not mutually exclusive. Specially considering that data structures are often designed for a purpose but a purpose does not necessarily require the same data structures – Christophe Dec 13 '19 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.