Communication Between Modules: Cohesion

Cohesion is a measure of the internal strength of a module; it indicates how closely the elements or statements of a module are associated with each other. Higher cohesion means strengthen/better module resultant.

Types of Cohesion

Types of Cohesion

There are seven types of cohesion:

1. Coincidental Cohesion
Coincidental cohesion occurs when elements are collected into a module simply because they happen to fall together.There is no meaningful relationship between the elements at all and so it is difficult to concisely define the function of the module.

File_processing
  open employee updates file
  read employee record
  print_page_heading
  open employee master file
  set page_count to one
  set error_flag to false
end

2. Logical Cohesion
Logical cohesion occurs when the elements of a module are grouped together according to a certain class of activity. That is, the elements fall into some general category because they all do the same kind of thing

Read_all_files(file_code)
  CASE of file_code
    1 : Read customer transaction record
        IF not EOF
	  increment customer_transaction_count
	ENDIF
    2 : Read customer master record
	IF NOT EOF
	  increment customer_master_count
	ENDIF
    3 :	Read product master record
	IF NOT EOF
	   increment product_master_count
	ENDIF
  ENDCASE
END

3. Temporal Cohesion
Temporal cohesion occurs when the elements of a module are grouped together because they are related by time.

Initialisation
  open transaction file
  read transaction record
  transaction_count = 0
  line = 0
  number = 0
END

4. Procedural Cohesion
Procedural cohesion occurs when the elements of a module are related because they operate according to a particular procedure. That is, the elements are executed in a particular sequence so that the objectives of the program are achieved

Read_student_record_and_total_student_ages
  set number_of_records to zero
  set total_age to zero
  read student record
  DOWHILE more records exist
    add age to total_age
    add 1 to number_of_records
  ENDDO
  print number_of_records, total_age
END

5. Communicational Cohesion
Communication cohesion occurs when the elements of a module are grouped together because they are all operate on the same (central) piece of data

validate_product_record
  IF transaction_type NOT=‘0’’ THEN
    error_flag = true
    error_message = ‘invalid transaction type’
    print_error_report
  ENDIF
  IF customer_number is NOT= numeric THEN
    error_flag = true
    error_message = ‘invalid customer number’
    print_error_report
  ENDIF
  IF product_no = blanks OR produc_no has leading blanks THEN
    error_flag = true
    error_message = ‘invalid product no’
    print_error_report
  ENDIF
END

6. Sequential Cohesion
Sequential cohesion occurs when a module contains elements that depend on the processing of previous elements.

Process_purchases
  set total_purchases to zero
  prompt and get number_of_purchases
  DO loop_index = 1 to number_of_purchases
    prompt and get pruchase
    add purchase to total_purchases
  ENDDO
  sales_tax = total_purchases*sales_tax_percent
  amount_due = total_purchases + sales_tax
END

7. Functional Cohesion
Functional cohesion occurs when all the elements of a module contribute to the performance of a single specific task.

Calculate_sales_tax
  IF price < $50 THEN
    sales_tax = product_price * 0.25
  ELSE
    IF price < $100 THEN
      sales_tax = product_price * 0.20
    ELSE
      sales_tax = product_price * 0.10
    ENDIF
  ENDIF
END
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s