I decided to use Code Metrics to measure cohesion and coupling.
Cohesion
For Cohesion, lets use metric called Lack of Cohesion of Packages (LCOP). It is modified version of LCOM4 metrics. It counts number of connected components (in this case classes) in each package:
The bigger value, the more cohesive package is. Note, that only directly connected components will count. For each approach we will get averaged values for every package. Here are measured values:
- Approach 1: 3/1 = 3
- Approach 2: (1+1+1)/3 = 1
- Approach 3: (3+3)/2 = 3
Approach 2nd has the lowest value, so it is the most cohesive.
Coupling
Now, lets measure coupling. For this we will use metric Coupling Between Objects (CBO). This metric is defined as:
The bigger value, the higher coupling between packages. We will count only efferent coupling. Again, values will be averaged in each approach. We have:
- Approach 1: 3/6 = 0.5
- Approach 2: (1/2+1/2+1/2)/3 = 0.5
- Approach 3: (0/3+6/3)/2 = 1
Aprroaches 1st and 2nd have the lowest value of coupling.
Summary
Approach 2nd is the most coehsive and just as good as 1st approach in coupling. Moreover, in practical use, approach 2nd will be easier to manage when the project will grow up. Quite suprisingly, approach 3rd seems to be the worst.