CS FundamentalsVery hardProduct company interview · GATE level

A class has fields a, b, c, d, e and methods m1 (uses a, b), m2 (uses b, c), m3 (uses d) and m4 (uses d, e). Using the Chidamber-Kemerer LCOM (number of method pairs sharing no field, P, minus the number sharing at least one, Q; 0 if negative), what is LCOM, and what does the field-sharing graph suggest?

  1. A. LCOM = 2; the methods form two separate groups, so the class could be split in two
  2. B. LCOM = 4; the class is fully cohesive
  3. C. LCOM = 2; all methods are connected, so no split is suggested
  4. D. LCOM = 0; the class is fully cohesive

Correct answer: A. LCOM = 2; the methods form two separate groups, so the class could be split in two

There are 6 method pairs. m1-m2 share b and m3-m4 share d (Q = 2); the other four pairs share nothing (P = 4). LCOM = 4 - 2 = 2. A non-zero LCOM signals poor cohesion, and the graph of shared fields has two components, {m1, m2 with a, b, c} and {m3, m4 with d, e} - two responsibilities in one class. 4 is P alone; a negative difference would be reported as 0.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic