10

I would like to start using DSM, but not sure how to get started.

What does a good dependency matrix look like and why? How does it work?

JavaRocky
  • 19,203
  • 31
  • 89
  • 110

4 Answers4

11

On this blog post Identify Code Structure Patterns with No Effort it is explained how to use a Dependency Structure Matrix to identify Code Structure Patterns. The screenshots are done with the Dependency Structure Matrix of the tool NDepend. Here are a few patterns:

Layered code (code with no cycle, certainly the coolest thing that a DSM can show you at a glance)
alt text

Code with dependency cycles
alt text

High Cohesion / Low-Coupling
alt text

Hungry Caller
alt text

Popular Callee
alt text

Mutual Coupling
alt text

Data Object
alt text

Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92
  • This is really helpful. Unfortunately, the images in the [linked article](http://codebetter.com/patricksmacchia/2009/08/24/identify-code-structure-patterns-at-a-glance/) are now missing, and were already missing in the first Wayback capture: https://web.archive.org/web/20110324091932/http://codebetter.com/patricksmacchia/2009/08/24/identify-code-structure-patterns-at-a-glance/ – seanf Dec 28 '18 at 05:01
  • I don't see any image missing, they are all here well displayed? – Patrick from NDepend team Jul 12 '19 at 09:21
  • 1
    Hi Patrick, I was referring to the missing images on the blog post: [Identify Code Structure Patterns at a Glance](http://codebetter.com/patricksmacchia/2009/08/24/identify-code-structure-patterns-at-a-glance/). The images here don't provide the full context, so I was hoping to find out more from the article. – seanf Jul 14 '19 at 23:06
  • 1
    See also Patrick's newer article https://blog.ndepend.com/identify-net-code-structure-patterns-with-no-effort/ which shares a lot of the same text and images, including some of the images above. (Archived as https://web.archive.org/web/20191003234718/https://blog.ndepend.com/identify-net-code-structure-patterns-with-no-effort/) – seanf Oct 03 '19 at 23:57
3

Erik Dörnenburg gives the best description I've seen, including some good examples of how arrangements of the graph can expose structural issues. Briefly:

  • as others have mentioned, anything above the diagonal indicates a cycle, which essentially means that your boundaries are "fuzzy" (not clean)
  • smallish squares (well, lower triangles) along the diagonal == good, if the components are grouped according to hierarchy
  • on the other hand, heavily weighted rows or columns == possible issues: either
    • rows: you have a component/group that lots of others depend on (maybe it's trying to serve too many features), or
    • columns: you have a component/group that depends on lots of others (maybe it's trying to take care of everything itself, instead of delegating)
Zac Thompson
  • 12,401
  • 45
  • 57
1

List the subsystems on the X and Y axis in the same order. Mark an "O" diagonally. Subsystems depending on themselves doesn't make much sense. Go vertically down the matrix. If that subsystem depends on the matching horizontal subsystem, mark an X.

A good one rearranges the subsystems to show patterns that might lead to a good refactoring.

I don't have one handy, though. Sorry.

Mike
  • 19,267
  • 11
  • 56
  • 72
1

One of the most valuable feature of a DSM is to detect cycles, for example between projects or packages. A cycle is displayed in the top-right side of the matrix. See this page for more details : http://docs.codehaus.org/display/SONAR/Dependency+Structure+Matrix

Simon Brandhof
  • 5,137
  • 1
  • 21
  • 28