This is a question about the concept of a function that performs only one thing. This will not make sense without some relevant passages for the context, so I will give them here. They are displayed on pages 37-38:
To put it another way, we want to be able to read the program as if it were a set of TO items, each of which describes the current level of abstraction and refers to the subsequent TO paragraphs at the next level down.
To enable settings and breaks, we turn on the settings, then turn on the contents of the test page, and then turn on the breaks. To enable the settings, we enable the set setup, if it is a set, then we turn on the normal setup.
It is very difficult for programmers to learn to follow this rule and write functions that remain at the same level of abstraction. But learning this trick is also very important. This is the key to keeping functions short and making sure they are "one." Making code read as the top set of TO paragraphs is an effective method for maintaining a level of abstraction.
He then gives the following bad code example:
public Money calculatePay(Employee e)
throws InvalidEmployeeType {
switch (e.type) {
case COMMISSIONED:
return calculateCommissionedPay(e);
case HOURLY:
return calculateHourlyPay(e);
case SALARIED:
return calculateSalariedPay(e);
default:
throw new InvalidEmployeeType(e.type);
}
}
and explains the problems with it as follows:
. -, , , . -, , . -, 7 (), . -, 8 (OCP), .
.
, , OCP, , . , , , SRP. , , , , - . " ". , , , "calculateHourlyPay()"
, - , , 3 , , : , , , , .. , OCP, , -, , , .
- , ?
.