![]() It’s like a developer, it doesn’t matter if it’s you or me, if we are developers and our responsibility is to develop but at the same time we do Marketing, yes, we are gods but we are not complying with the Single Responsibility Principle! Why you should follow the Single Responsibility Principleīy implementing SRP in the code you can achieve several benefits at the code level and also save time. If you have a class in C# that does X thing and also does Y thing, I would suspect that you are not complying with the Single Responsibility Principle. “Enforce that a class only does one thing” ![]() This helped us adhere to the Single Responsibility Principle and improved the overall design of our code.Even though this single reason to change sounds a bit weird (and Martian in my opinion□), so self-explained will be: PlotOnCanvas to handle the plotting functionality, and moved the relevant function from the Circle class to the new class. In the C# example provided, we saw how the Circle class had a function that was not directly related to the circle'sįunctionality, and therefore violated the Single Responsibility Principle. When you'reĬoding, always ask yourself what the responsibility of the class is, and if it has multiple responsibilities, consider breaking it up into smaller ones. This makes the code more readable, flexible, and maintainable. It states that every class, module, component, or microservice should have one specific In the SOLID principles of object-oriented programming. In this article we learn't what is SOLID principles.In conclusion, the Single Responsibility Principle is an important concept
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |