Invoice
- items
- total
+ calcTotal()
+ saveToDB()
+ toPdf()
+ emailTo(c)
The god class
1class Invoice {2 calcTotal(){ ... } // business math3 saveToDB(){ ... } // persistence4 toPdf(){ ... } // layout5 emailTo(c){ ... } // email6}
Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.
Try one problemA class should have ONE reason to change. Bundle one responsibility per class; split it the moment a class starts juggling many.
1class Invoice {2 calcTotal(){ ... } // business math3 saveToDB(){ ... } // persistence4 toPdf(){ ... } // layout5 emailTo(c){ ... } // email6}
Here is Invoice. It compiles, it works, and at a glance it looks like a perfectly normal class — just a busy one. So what is wrong with it?