4

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?

x1886x
  • 1,217
  • 2
  • 12
  • 21

2 Answers2

1

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.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • I see what you mean regarding the validity of cleanUtensils and makePhoneCall. The point of my question was not so much to do with the actual content of the methods themselves but with the structure of the main prepareHolidayMeal method. ie Assuming all the operations are valid and necessary, does moving them into their own methods change the type of cohesion from procedural to functional? – x1886x Oct 17 '12 at 22:14
  • cohesion means "stuck together" - if you unbundle them things are better. As soon as you start bundling again you need to be careful. You can still create new bundles which is at least helpful. The follow up problem might be that information hiding is broken then. So you need a good balance. – Wolfgang Fahl Oct 18 '12 at 14:16
1

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".

Tengiz
  • 8,011
  • 30
  • 39