SOLID principles basically form the fundamental guidelines for buildingย
๐ object-oriented ,ย
๐ loosely coupled ,ย
๐ robust, maintainable andย
๐ easily understandable applications .
๐ ๐๐ฅ๐๐ฌ๐ฌ ๐ฌ๐ก๐จ๐ฎ๐ฅ๐ ๐ก๐๐ฏ๐ ๐จ๐ง๐ ๐๐ง๐ ๐จ๐ง๐ฅ๐ฒ ๐จ๐ง๐ ๐ซ๐๐ฌ๐ฉ๐จ๐ง๐ฌ๐ข๐๐ข๐ฅ๐ข๐ญ๐ฒ.ย
We should write, change or maintain a class for only one purposeย
which gives us the advantage of cleaner ,robust code andย
fewer test cases as to we know which functionality is covered in which class and which class would be modified in case of a change.ย
For ex:
๐๐ข๐๐๐๐ ๐๐๐๐ ๐ Calculator{
๐๐ข๐๐๐๐ ๐ฃ๐๐๐ ๐๐๐๐๐ก๐ท๐๐ก๐๐๐๐ () {}
๐๐ข๐๐๐๐ ๐๐๐ข๐๐๐ ๐๐๐๐๐ข๐๐๐ก๐() {}
๐๐ข๐๐๐๐ ๐ฃ๐๐๐ ๐๐๐๐ก๐๐ท๐ต() {}
}
Above class has three separate responsibilities:ย
โprinting,ย
โcalculation andย
โadding to database.ย
By applying SRP, we can separate the above class into three classes with separate responsibilities.