Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
roth_stephan_clean_c20_sustainable_software_development_patt.pdf
Скачиваний:
29
Добавлен:
27.03.2023
Размер:
7.26 Mб
Скачать

Chapter 6 Modularization

requirement regarding the graphical user interface has to be implemented, then this class has obviously too many responsibilities.

Another type of aspect relates to the system’s domain. If the same software unit must be changed, either because there are new requirements regarding the customer management, or there are new requirements regarding the invoicing, this software unit has too many responsibilities.

If we look again at the general hierarchical decomposition of a system as depicted in Figure 6-1, we can see that on every hierarchy level, every depicted part and software unit should have one well-defined and clear responsibility.

Single Level of Abstraction (SLA)

The principle of Single Level of Abstraction (SLA) states that each software unit—and this includes all units mentioned in the section on the SRP—should be composed of parts that are all at the next lower level of abstraction.

Software units usually have different levels of abstraction. For example, take a method of a class. The instructions within this method should all be at the same level of abstraction. Assigning a value to one of the class’s attribute is on a lower level of abstraction than calling another method from within that method. The reason for this is that a method call can conceal the execution of a significant amount of complex logic.

If you take a look at the literature, the SLA is always only explained on the basis of the lines of code within a function or method. However, the principle should also be applied to the software units above the functions and methods, e.g., to larger software components. The building blocks that make up the software component, maybe a bunch of collaborating classes, should all be at the same next lower level of abstraction.

Why is this principle important?

First of all, the single level of abstraction fosters the readability of the code significantly. Mixing levels of abstraction can be very challenging for readers of the code, because our brain must permanently handle a mental shift between thinking about higher-level concepts and low-level implementation details.

Another great advantage is that SLA harmonizes extremely well with the aforementioned principles SRP, the practice of hierarchical decomposition, and especially with the domain-centric approach.

226