Package Tangle Index
Package Tangle Index
This metric tells you how many cycles exist between different Java packages. A cycle is defined as a circular dependency between two packages, one depending on the other and vice versa.
Why care?
- Tells you how likely making a change will break something; have unforeseen consequences.
- Makes refactoring very difficult
How it happens
Let's take the example of a program developed with the Domain Driven Design pattern. We start off with 3 layers.
- DAO
- Repository
- Service Layer
Transaction logic is put in the service layer. Starts absorbing business rules. So we push it down further into the model. Service layer seems pristine and focuses on one thing.
But then more requirements come in. Model relationships must be implemented. (ie. Line items vs. orders) We want to find all line items for a given order. The model starts depending on repository
  Service -> Repo -> Model -> Repo
How to see it?
Sonar calls these Directory Tangle Index. Anything above the downwards diagonal is a circular dependency.
How to fix it
Click on one of the red value in the cycle matrix. It will highlight the offending counterpart in the corresponding package.
A list of files is displayed. These are where the dependencies must be cut.