CBO — Coupling Between Object Classes
Class Metric | AST-based
Count of distinct external types referenced in a class's structural interface — heritage clauses, property-type annotations, and method-signature parameter/return types. Body-level type usage (inside statement blocks) is intentionally excluded to measure structural coupling, not operational coupling.
Formula
CBO = |distinct external type references|
The class's own name is removed from the set. Primitive types (string, number, boolean, etc.) are excluded naturally because they are represented as predefined_type nodes rather than type_identifier nodes.
What counts
| Source | Included? | Example |
|---|---|---|
| Heritage clause | ✅ | extends Base, implements IFoo |
| Property type annotation | ✅ | name: UserDto |
| Method parameter type | ✅ | fn(x: OrderService) |
| Method return type | ✅ | (): Result<T> |
| Body call expressions | ❌ | new HttpClient() inside method body |
| Primitives | ❌ | string, number |
TypeScript Example
class OrderController extends BaseController
implements IController {
private svc: OrderService; // +1
private log: Logger; // +1
process(dto: OrderDto): Result<Order> { ... }
// +3 from heritage, +2 from props, +3 from method sig
// unique: BaseController, IController, OrderService, Logger, OrderDto, Result, Order
// CBO = 7
}
Thresholds
CBO is informational — there are no configurable thresholds for it. High values (> 7–10) suggest the class is a coupling hub that will be brittle to change.