Contract-Driven Development ✍️
Contract-Driven Development (CDD) is a software development methodology that relies on defining formal interfaces and contracts between software components to ensure proper integration. The key principles of CDD are:
-
Define clear interface contracts upfront - All components expose interfaces defined in a shared contract. This enables integration.
-
Design by contract - Modules make guarantees about behavior via contracts. Enables testability.
-
Code generation - Contracts are used to generate models, stubs and tests. Keeps implementations in sync.
-
Contract versioning - Contract owners version contracts and manage change impacts.
-
Language agnostic - CDD does not depend on any particular programming language.
-
Enables team independence - Teams can develop components independently if contracts are followed.
-
Facilitates design reviews - Design Advocates can focus on what matters the most to them.
-
Allows implementation flexibility - Teams can choose their preferred implementation style and stack while satisfying common contracts. A team depending on Java 11 could be code generating with optionals where a cutting-edge team on Java 17 could generate with records or any new addition to the language
Example - OpenAPI
OpenAPI is an API specification format that allows defining interface contracts for RESTful APIs in a language-agnostic way, enabling documentation, code generation, and integration between components.
openapi: 3.1.0
info:
title: Sample API
version: 1.0.0
paths:
/users:
get:
summary: Returns a list of users
responses:
200:
description: Success
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
email:
type: string
required:
- id
- name