7/27/2023 0 Comments Single responsibility principleWhen we implement SRP in our code, our methods become highly related (coherent). Furthermore, with such a code, testing becomes easier as well. As we reduce code complexity, our code becomes readable and therefore maintainable.Īs we could see from our example, if our class does its job well, we can reuse its logic in a project. Because we are trying to accomplish only one task in our class, they have become free of clutter and simple to read. The first one being that it has become less complex. Our code has improved in several ways by implementing SRP. Benefits of Single Responsibility Principle Now every class we have is responsible for one thing and one thing only. Var saver = new "WorkReport.txt", "Schedule.txt", scheduler) Īfter we execute this code, we will have our file saved in a required location on a defined schedule. String.Join(Environment.NewLine, _entries.Select(x => $"Code: ) Public void RemoveEntryAt(int index) => _entries.RemoveAt(index) Public void AddEntry(WorkReportEntry entry) => _entries.Add(entry) The next step is creating a WorkReport class which will handle all the required features for our project: public class WorkReport So we are going to start with a simple model class: public class WorkReportEntry Imagine if we have a task to create a work report feature that, once created, can be saved to a file and perhaps uploaded to the cloud or used for some other purpose.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |