I am trying to understand the Direct Class Coupling (DCC). I try to to calculate the DCC metrics for a class diagram but I don't know how the article that I read obtained value 2:
Can someone explain me how to calculate it?
I am trying to understand the Direct Class Coupling (DCC). I try to to calculate the DCC metrics for a class diagram but I don't know how the article that I read obtained value 2:
Can someone explain me how to calculate it?
The Direct Class Coupling metric is a metric that measures the dependency of a class to other classes of the system. The more dependencies with other class, the more difficult it'll get to reuse that class or to maintain it. While I didn't find the original article of Bansiya and Davis in 2002 that defines it, I found its description in other academic papers, as well as in a DDJ article of 1997 in which Bansiya & Davis describe a tool that calculates metrics automatically from source code:
count of the different number of classes that a class is directly related to, including those related by attribute declarations and message passing (parameters) in methods.
Moreover its similarity with CBO (Coupling Between Object classes), in particular regarding inheritance which is not counted in the coupling, and regarding multiple relations between the same classes that are counted only once, lead to the following analysis:
EntryStation
has only attributes of primary types: no couplingUser
: no couplingATM
is associated with Consortium
(shared aggregation) and has a CashierStation
attribute: coupling with 2 classesCashierStation
has an EntryStation
attribute and a Branch
attribute ans is also associated with Branch: coupling with 2 classesConsortium
is associated with ATM
and has Branch
, EntryStation
and User
attributes: coupling with 4 classes !Branch
is associated and has a CashierStation
attribute. It has ATM
and User
attributes: coupling with 3 classes !So looking at the diagram overall, the maximum coupling is 4. The total number of couplings would be 11. The average per class would be 1.83, not far from 2, but still not 2.
Following your referenced article, I've removed the list of possible alternative counting of my previous answer.
The article shows DCC which have decimals, which can therefore not be the count of couplings as originally defined. It explains (Table 3.3.) that the formula used to evaluate an UML model is:
Summ(NumAttrandParam) / NumCls
The second element is the number of classes in the package, according to the metrics definition of the SDMetrics software the author used. This is clearly 6.
The first element, is according to the author an adapted metric calculated with custom code. Considering that the SDMetrics doesn't have a NumAttrandParam
metric, but that the NumAttr
metric is simply a count of the attributes, I could imaging that there is a bug in this metric: for example if he counted each attribute even if it has the same class, it would compute in total 12 couplings because of the 2 ATM in Branch, which would then result in an average per class of 2.