![]() ![]() Throw new Exception("Name is not || !email.Contains(".")) ![]() If(String.IsNullOrWhiteSpace(firstName) || String.IsNullOrWhiteSpace(lastName)) Public void SendInvite(string email, string firstName, string lastName) A Simple ExampleĬonsider the following class: public class InvitationService ![]() This results in high-cohesion and low-coupling code, an ideal situation when changes arise (as they inevitably do) because it minimizes the impact any changes have on the affected code and its related modules. This means that high coupling means that modules are more dependent upon one another, and low coupling means they are less dependent.Įssentially, following SRP minimizes the possible times more than one class will have to change for a given requirement, and maximizes the possibility that changing one class will not impact any other classes. Having a class with many methods that do one job (or aspects of one job, depending on your definition) means that that class has high cohesion.Ĭoupling is the manner of independence between modules of a programming system. This means that the level of cohesion between elements is higher if they are related, and lower if they are not. The primary benefit the Single-Responsibility Principle gives you is high-cohesion, low-coupling code.Ĭohesion refers to the degree with which elements of code belong together. If a class has more than one reason to change, it should be refactored. The Single Responsibility Principle (SRP) states that any class must have one, and only one, reason to change. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |