Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: Rank the cohesion (20 minutes)
Rank from best to worst: a module that only computes shipping cost; a module of start-up jobs; a module called Misc; a module that parses a file and then validates the result.
Done when: a ranking with the kind of cohesion for each.
Hint
Functional is best, coincidental is worst.
Easy 2: Count the ties (20 minutes)
Class A calls B, C and D. Class E and F call A. Find Ca, Ce and I for A.
Done when: three numbers.
Hint
Incoming is the callers, outgoing is the callees.
Easy 3: Name the connascence (20 minutes)
Name the kind: two services both hard-code that status 2 means "refunded"; a function takes (width, height) and callers swap them; two threads update one counter.
Done when: three names with static or dynamic.
Hint
Hard-coded meanings and swapped values are static. A race is dynamic.
Medium
Medium 1: Compute D (30 minutes)
Module X has Ca 6, Ce 2, 1 abstract and 9 concrete elements. Find I, A and D. In which zone is it? Suggest one change.
Done when: three numbers, a zone and a change.
Hint
I = 2/8 = 0.25, A = 1/10 = 0.1, so D = |0.1 + 0.25 - 1| = 0.65.
Medium 2: Split or keep (30 minutes)
A Customer module has add, update, get, notify, get orders, cancel orders. Use the three questions from FSA to decide whether to split. State the facts you would need.
Done when: a decision, three facts and a statement on coupling.
Hint
Ask whether orders will grow and whether they need much customer data.
Medium 3: Strengthen the weak (30 minutes)
A code base has magic numbers for user roles in 40 places. Describe the refactor, its connascence before and after, and what check (fitness function) could stop new magic numbers.
Done when: before and after kinds, a refactor plan and a check.
Hint
Named constants turn meaning into name.
Hard
Hard 1: Review a Common package (45 minutes)
A Common package has 60 classes and is used by 25 modules. Plan a review: metrics to take, how to find the groups inside it, how to split it with the least breakage, and how to confirm the result.
Done when: a five-step plan with metrics before and after (made up).
Hint
Look for clusters of classes that are used together.
Hard 2: Distributed connascence (45 minutes)
Two services share a database table. Name the connascence kinds this creates (at least three), rate strength, locality and degree, and propose a change that weakens each.
Done when: a table of three kinds with ratings and fixes.
Hint
Shared tables create name, type and meaning ties, and also timing ties.
Hard 3: Metrics lie (50 minutes)
Give two cases where a good metric value hides a real problem, and two where a bad value is acceptable. Explain with the FSA warning on interpretation.
Done when: four cases with reasons.
Hint
A balanced metric can sit on top of the wrong boundaries.