![]() That is the trick to be able to implement SRP in our apps or developments: know the responsibility of each class. How To Implement Single Responsibility Principle in C#įollow the Single Responsibility Principle in C# is easy as long as you know the responsibility of each class. This can be achieved thanks to the dependency injection getting a more testable and extensible code. Facilitates code extension: If the Sigle Responsibility Principle is met in C#, we have the possibility to combine these classes and build a more user-friendly and modular code.That is, a method will not depend on another method and this makes them more independent of each other. Reduces coupling: If methods only do one thing, one of the things we C# developers will avoid is coupling.By respecting SRP we will find that writing unit tests in the class is an easy task since the class only does one thing and not several and therefore, reduces bux fixes and reduces testing time. Makes testability better: As any good C# developer we know that writing and running unit tests is always advised and considered good practice.You don’t have to worry that changing one thing will break another. ![]() If the class does only one thing, you will only have to see to it that you modify that one thing and check that it works well. ![]() If for any reason that class has to be modified, it will most likely return errors that did not happen before. Enhaces maintenance and scalability: If we think for a second about a class that violates the SRP, we will think about a class that does many things.This allows you to have a “ cleaner” brain of information and allows you to think and manage the project or application better. When a class has only one responsibility, your developer brain will only have to think about that one responsibility and no more. ![]()
0 Comments
Leave a Reply. |