![]() ![]() ![]() The snippet above is a fragment of the code component that makes up the folder tree. What’s the best way to stick to this principle? Before each code change (or when we sit down to write a new one), just ask yourself: what responsibility does this code have? If there is more than one “and”, then it is most likely suitable for refactoring. We aim to make as few changes as possible (because every change involves changing classes/components depending on the changed object).Ĭlasses/Objects with one responsibility are: reduces the number of changed classes (the more responsibility a class has, the more often it will be changed).the code is easier to write (because we cover less functionality within one file than one file with many),.Repeating after Robert Martin – when creating our code, we should write it in such a way that if the requirements change, the class only has one reason to change. “A class should have one, and only one, reason to change”. But that doesn’t mean we should proceed that way. It stands for the Single Responsibility Principle.Īs illustrated above, we can have a code (a class/a method) which is like a pocket knife – it’s able to do everything. It’s worth acknowledging them in your everyday work as an Angular developer.įirst comes the letter S. Although most of the principles have existed since the last century, they are still valid and are one of the most important elements of object-oriented programming. SOLID is a set of principles thanks to which we can create a code that is scalable, can be extended easily, and change implementations of existing mechanisms. ![]()
0 Comments
Leave a Reply. |