Turning sequential cohesion into functional cohesion?

677 Views Asked by At

As described on this website,

A module with (only) procedural cohesion is one supporting different and possibly unrelated activities, in which control passes from one activity to the next. Page-Jones gives an example of a module (whose name might be something like, ``Prepare for Holiday Meal:''

  • Clean Utensils from Previous Meal
  • Prepare Turkey for Roasting
  • Make Phone Call
  • Take Shower
  • Chop Vegetables
  • Set Table

Now my question is, if each of those activities, ie make phone call, are extracted into their own method, but all are still called in that same order ie

    private void PrepareForHolidayMeal()
    {
    CleanUtensilsfromPreviousMeal();
    PrepareTurkeyforRoasting();
    ...
    SetTable();
    }

is this method still an example of procedural cohesion? Or is it functionally cohesive as it supports the activites for the execution of one problem related task, in this case preparing for a meal?

2

There are 2 best solutions below

2
On

The phone call is left out in your example for good reason. It's one of the unrelated tasks. If you assume the phone call is still in "..." than the whole thing would loose its cohesion again. Otherwise you might argue that all the other activities are necessary for preparing a meal. This might start a discussion whether "CleanUtensilsfromPreviousMeal" is actually valid here because this activity might only be necessary in the circumstance that there was no cleanup before. StackExchange questions are not for such discussions thow ... so we would need a far clearer example for the decision to be agreed on by multiple software architects. Otherwise some people might argue different than others.

0
On

This is a very interesting question, and yes, the answer is relative and depends on the way we understand things [written in the article] and how they correspond to what the author meant.

Particularly between procedural and functional cohesions, there's a slight difference: procedural cohesion is something which contains steps unrelated to each other, i.e. there is no "goal" for the procedure which is something repeatable and would be needed to have it "fixed defined" and re-used. Whereas, functional cohesion is basically a function (probably accepting input and giving an output) which can be used for different inputs and will produce the correct output (depending on the input) when re-used.

Conclusion, as per your question: no, putting each in separate methods and calling them in the same order does not change it from procedural to functional, unless your procedure becomes a function which really has some "goal".