THINK FIRST·CODE LATER

← All labs

Coupling metrics and layer violations

Problem

Analyse StudyBuddy's module dependencies.

Input:

LAYERS presentation service domain data
<lines: module layer>
DEPS
<lines: from to>   (module "from" depends on module "to")

The LAYERS line lists the layers from top to bottom. A module may depend only on modules in the same or a lower layer.

Output, for each module in the order it was declared:

module: fan-in=Ca fan-out=Ce instability=I

with I = Ce / (Ca + Ce) printed with two decimals (0.00 if Ca + Ce = 0). Duplicate dependency lines count once. Then the violations in input order, VIOLATION: from (layerA) -> to (layerB), or No layer violations.

Input:

LAYERS presentation service domain data
web presentation
board service
post domain
repo data
DEPS
web board
board post
board repo
post repo
repo web

Output:

web: fan-in=1 fan-out=1 instability=0.50
board: fan-in=1 fan-out=2 instability=0.67
post: fan-in=1 fan-out=1 instability=0.50
repo: fan-in=2 fan-out=1 instability=0.33
VIOLATION: repo (data) -> web (presentation)

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.