For example, functions drawCircle and drawTriangle are cohesive enough to belong to the same module responsible for drawing, and it feels natural to put these two functions close to each other in the code (high similarity ~ high cohesion).Ĭoupling, on the other hand, is the measure of dependence of the part on the rest of the system (low dependence ~ loose coupling). The application of the Separation of Concerns involves two processes: reduction of coupling and increasing cohesion.Ĭohesion is the measure of similarity by the set of duties, level of details, and locality. The process very much resembles what we had to do for functions: estrange less-closely related functionality and group up the features serving the same distinct purpose. SoC for modulesĪt a bit higher level, this principle tells us to group the functions under self-contained modules, each responsible for the fulfillment of a single set of tasks that have a clear logical correlation. We gain the code clarity, and chunks of the algorithm eventually become reusable by other parts, even if we initially didn’t expect this to happen. During this process, parts of the original algorithm get exported and encapsulated in separate smaller functions with a private access level. In such a case SoC pushes us to refactor it, turning into a more laconic and descriptive revision. When the function starts to bloat up in size, this is the red flag that the method is possibly taking care of too many things at once. SoC instructs us to avoid writing long complex functions. If we take the lowest level (the actual programming code), In this article, I elaborate on applying this profound principle at all levels of abstraction: from the programming code inside each function and the design of the modules to the overall app’s architecture, all for achieving the characteristics of what we call a qualitative software. The principle is simple: don’t write your program as one solid block, instead, break up the code into chunks that are finalized tiny pieces of the system each able to complete a simple distinct job. It is so crucial that 2 out of 5 SOLID principles (Single Responsibility and Interface Segregation) are direct derivations from this concept. The separation of concerns (SoC) is one of the most fundamental principles in software development.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |