S — From SOLID principles 1/5

By Published On: March 13, 2023Categories: Development

The single responsibility principle states that your classes and functions should have only one reason to change. To put it another way, your classes and functions should do one job at a time.

I’ve attached an image where I demonstrated by writing left side doing two different tasks in one class and function. Auth and Log. This clearly breaks the rule as one can change the function of this class for two reasons.

1) Authentication

2) Logging

Now see on the right side I split one class into two giving them a single job each. Clean. #CleanCode #SRP #SOLID_PRINCIPLE

Share this article

Written by : admin

Leave A Comment

Latest Articles