PricingDownload
Product

Platform

All features48 capabilities, from IDE to CICompliance KitsISO 26262, DO-178C, IEC 62304...AI GovernanceControl AI-generated C/C++ codeWhat’s new in 2027Latest version highlightsScreenshotsSee the product in action

Analyze & improve

Coding standardsMISRA, CERT, CWE, AUTOSARArchitecture & dependenciesGraphs, matrix, cyclesSBOM & dependenciesIs our C++ code affected? Minutes, not weeksTechnical debtMeasured in hours and dollarsQuality gatesStop regressions in CISmart Code CityYour codebase in 3D

Integrations

IDE pluginsVisual Studio, VS Code, CLion...CI/CD pipelinesJenkins, Azure DevOps, GitHub, GitLabSonarQube pluginC/C++ results in SonarQubeExternal analyzersClang-Tidy, Cppcheck, coverageFeature on Demand
Solutions

By need

Functional safetyCompliance kits per standardCoding standardsMISRA, CERT, AUTOSAR, ISO...Legacy modernizationRefactor large C/C++ safelyCode auditExpert review of your codebaseM&A due diligenceAssess technical health fast

By role

DevelopersSoftware architectsTech leadsDevOps engineersEngineering managersProject managers

CTOsCIOs / IT leadersQA engineersSecurity leadersComplianceConsultantsRequest a guided PoC
Industries

Safety-critical

AutomotiveISO 26262, MISRA, AUTOSARAerospace & DefenseDO-178C programsMedical DevicesIEC 62304 softwareEnergy & UtilitiesIEC 61508 systemsEmbedded SystemsFirmware and devices

Enterprise

Financial ServicesTrading and paymentsGame DevelopmentEngines and large C++Software VendorsCommercial C/C++ productsGovernmentAgencies and contractorsAll industries & case studies
Resources

Learn

DocumentationGuides, rules and CI setupKnowledge baseFrequently asked questionsBlogC and C++ code quality articlesRelease notesEvery version since 2009

Customers

Case studiesSuccess storiesTestimonialsWhat users sayOur customersCompanies using CppDependGold Code QualityOpen source projects we rate

Programs & company

Feature on DemandMissing features built for freeFree for open sourceLicenses for OSS and studentsContact usSales and supportEULALicense agreement
Docs
Documentation

Design and Architecture

Abstractness vs Instability

A chart that tells, for each part of your code, whether its stability matches its level of abstraction. Stable code that cannot be extended becomes painful to change. Abstract code that nobody uses is useless. The chart shows both at once.

5 min readDesign and ArchitectureCppDepend 2027

Abstractness vs Instability chart in CppDepend

What it shows

Each point is a unit of code (a project or a namespace, depending on the level you choose). The horizontal position is its abstractness, the vertical position is its instability. A dashed line, the main sequence, joins the two ideal corners. The closer a point is to this line, the better balanced it is. The metrics are the ones defined by Robert C. Martin.

The metrics

Instability (I)

I = Ce / (Ca + Ce)
  • Ca (afferent coupling): how many other units depend on this one.
  • Ce (efferent coupling): how many units this one depends on.

I goes from 0 to 1. 0: many depend on it and it depends on nothing, it is very stable and costly to change. 1: it depends on others and nobody depends on it, it is unstable and cheap to change. Neither is bad by itself: a top-level application should be unstable, a core library should be stable.

Abstractness (A)

A = abstract types / all types

A goes from 0 (only concrete types) to 1 (only abstract types). An abstract type is one that cannot be instantiated and exists to be implemented or extended: an interface, an abstract class.

Distance from the main sequence (D)

D = | A + I - 1 |

D goes from 0 (on the line) to 1 (in a far corner). It is a single number to sort by: the highest D are the units to look at first.

UnitAIDVerdict
Application, main0.01.00.0Fine: concrete and unstable
Interface-only library1.00.00.0Fine: abstract and stable
Core utilities, all concrete, used everywhere0.050.10.85Zone of pain
Interfaces that nobody uses0.90.950.85Zone of uselessness

Reading the chart

Abstractness (A) Instability (I) 01 01 Zone of pain Zone of uselessness Main sequence app driver api util

The two zones

ZoneWhereWhy it hurtsTypical case
Zone of painBottom left: stable and concreteMany depend on it, so every change is risky, and there is no abstraction to change it behind. The code is rigid.A shared utilities library, a data layer used directly everywhere.
Zone of uselessnessTop right: unstable and abstractAbstractions that nobody uses. They cost maintenance and give nothing.An interface layer designed "for later", abandoned classes.
Not every point in the zone of pain is a problemStable concrete code that never changes is harmless: a string library, a math library, generated code. Look at the units that are in the zone and that change often.

In C and C++

  • Abstract type: a class with at least one pure virtual function (= 0). Templates, concepts and function pointers also create abstraction in C++, but they are not counted as abstract types, so a template-heavy library can look more concrete than it is.
  • Header-only libraries: their types are usually concrete templates. A low A there is expected and does not mean poor design.
  • C code: there are no abstract classes. Units written in C will always have A = 0, and only the instability tells something. Read D with that in mind.
  • The unit: choose namespaces for a code base that uses them, or projects for a code base with one library per folder. Code in the global namespace is a single unit, which hides its structure.
  • Third party and generated code: exclude them (see the project excludes), otherwise they dominate the zone of pain.

What to do

A unit is in the zone of pain

  1. Find what changes most in it (history, or the issues view).
  2. Put an abstract interface in front of the part that changes, and make the users depend on the interface.
  3. Run the analysis again: A goes up, and the dependents now depend on an abstraction.

A unit is in the zone of uselessness

  1. Check who uses its abstract types (Ca is low).
  2. Remove the abstractions nobody implements or uses, or move them next to their only user.

A unit is far from the line but fine

Use the exceptions of your rules (for example for generated code), and keep the rest of the rule active. Do not disable the rule for the whole project.

Rules (CQLinq)

The same metrics are available in CQLinq, so you can fail a quality gate when a unit is too far from the main sequence.

// Namespaces far from the main sequence
warnif count > 0
from n in Application.Namespaces
let a = n.Types.Count(t => t.IsAbstract) / (double) System.Math.Max(1, n.Types.Count())
let ce = n.NamespacesUsed.Count()
let ca = n.NamespacesUsingMe.Count()
let i = ce / (double) System.Math.Max(1, ca + ce)
let d = System.Math.Abs(a + i - 1)
where d > 0.7 && n.Types.Count() >= 5
orderby d descending
select new { n, A = a, I = i, Distance = d, ca, ce }
Small unitsWith few types, A and I jump with a single type. The rule above ignores units with fewer than five types. Raise this number on small projects.

Limits

  • The metrics measure structure, not quality: a unit on the main sequence can still be badly designed.
  • Coupling is counted between units, not between types: a unit with one heavily used class and many unused ones has the same Ca as one where all are used equally.
  • The result depends on the unit you choose and on what you exclude.
  • Use it to find where to look, and combine it with the dependency cycles and the Architecture Blueprint.

Questions

Everything is at A = 0. Is it a bug?

No. A project without abstract classes (pure virtual functions) has A = 0 everywhere. This is usual for C code and for code built on templates. Only the instability and the cycles are useful there.

Which value of D is too high?

As a rule of thumb, look above 0.7 and ignore very small units. Compare the trend between two analyses rather than the absolute value.

The utilities library is in the zone of pain. Must I change it?

Only if it changes often. A stable concrete library that is rarely modified is not a problem in practice.

What is the difference with the dependency cycles rule?

Cycles say who depends on whom in a loop. This chart says whether a unit is too rigid or too abstract for its position. Both are needed.

Was this page helpful?
Evaluating CppDepend on a production codebase?Get a guided proof of concept with our static analysis architects.
Request a PoC