More WET, less DRY

Svaťa Šimara
Mar 1 · 6 min read

Don’t repeat yourself

Car in API

{
"vin": "4Y1SL65848Z411439",
"make": {
"key": "vw",
"name": "Volkswagen",
"shortName": "VW"
},
"model": {
"key": "arteon-shooting-brake",
"name": "Arteon Shooting Brake",
"shortName": "Arteon"
},
"color": {
"key": "black",
"name": "Black"
}
}

Inheritance in OOP

Class Diagram

Traits in PHP

Composition

Couple of months later

{
"vin": "4Y1SL65848Z411439",
"make": {
"key": "vw",
"name": "Volkswagen",
"shortName": "VW",
"uuid": "6418f26a-e04d-42f6-b16e-bb19ff07c10e",
"catalogueId": 1000
},
"model": {
"key": "arteon-shooting-brake",
"name": "Arteon Shooting Brake",
"shortName": "Arteon",
"modelFamily": {
"family": "MODELFAMILY_ARTEON_SHOOTING_BRAKE",
"familyGroup": "MODELFAMILYGROUP_ARTEON",
"edition": "MODELFAMILY_ARTEON_SHOOTING_BRAKE_1_6"
}
},
"color": {
"key": "black",
"name": "Black",
"hexCode": "#000000",
"ral": "9005"
}
}

Benefits

Problems

Add w̵a̵t̵e̵r̵ code and make it WET again

Problems

Benefites

Class Diagram

DRY misuse

API

Computation

DL;DR

Resources

Traits in Practice

Carvago Development

Lessons learned and stories from Carvago development team