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?
- A. LCOM = 2; the methods form two separate groups, so the class could be split in two
- B. LCOM = 4; the class is fully cohesive
- C. LCOM = 2; all methods are connected, so no split is suggested
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- main has commits A-B-C-D-E (E is main's tip). feature was created at C and got commits F and G; then main was merged into feature…
- A service runs on 3 identical servers, each 95% available and failing independently; it works when at least 2 of the 3 are up (a majority…
- A system needs all three of its components to work. Their failure times are exponential with MTTFs of 2,000, 5,000 and 10,000 hours. What…
- Two inspectors review the same document independently. Inspector 1 finds 30 defects, inspector 2 finds 24, and 12 defects are found by…
- To estimate remaining defects, 20 artificial defects are seeded into a program. Testing then finds 15 of the seeded defects and 45 genuine…
- In a class hierarchy, B, C and D extend A; E and F extend B; G extends E; H extends C. Using the Chidamber-Kemerer metrics with DIT(A) =…