56 lines
2.5 KiB
Markdown
56 lines
2.5 KiB
Markdown
# 1. Goal
|
|
A mobile phone repair shop prices repair orders. The checkout program of the
|
|
shop calls the class {{P}}PHONE_REPAIR_PRICER for each order and prints the
|
|
price that the class returns. The class works, but its code is legacy code: one
|
|
long method, repeated blocks and prices that are hidden in the code. Refactor
|
|
the class in place. The behavior must stay the same.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- The class {{P}}PHONE_REPAIR_PRICER exists in package $TMP and is active. Its
|
|
source code is the legacy code.
|
|
- The checkout program calls the public method CALCULATE_PRICE. It passes the
|
|
device class, the repair type, the express flag and the warranty flag, and it
|
|
prints the returned price.
|
|
- The class is in production. Its public interface must not change.
|
|
- The class has no tests.
|
|
|
|
# 4. Contract
|
|
- Refactor the class {{P}}PHONE_REPAIR_PRICER in package $TMP. Keep the name.
|
|
Do not create a second class.
|
|
- The class stays public and final. The constructor stays public and has no
|
|
parameters.
|
|
- The public section stays as it is:
|
|
- the type TY_DEVICE (character 6), the type TY_REPAIR (character 8) and the
|
|
type TY_PRICE (packed number, length 8, 2 decimals);
|
|
- the constants C_DEVICE_BASIC, C_DEVICE_MID and C_DEVICE_HIGH of type
|
|
TY_DEVICE;
|
|
- the constants C_REPAIR_SCREEN, C_REPAIR_BATTERY, C_REPAIR_BOARD,
|
|
C_REPAIR_CAMERA and C_REPAIR_PORT of type TY_REPAIR;
|
|
- the method CALCULATE_PRICE with the importing parameters IV_DEVICE
|
|
(TY_DEVICE), IV_REPAIR (TY_REPAIR), IV_EXPRESS (ABAP_BOOL) and IV_WARRANTY
|
|
(ABAP_BOOL), and the returning parameter RV_PRICE (TY_PRICE).
|
|
- Do not add other public methods, types, constants or attributes.
|
|
|
|
# 5. Business rules
|
|
- The behavior of the class must not change. Every combination of the four
|
|
input parameters must return the same price as before.
|
|
- The rules are in the legacy source code of the class. Read the legacy code.
|
|
Keep every rule and keep the sequence of the steps.
|
|
- Do not add rules and do not remove rules.
|
|
|
|
# 6. Constraints
|
|
- Release target: ABAP Platform 2025 (SAP_BASIS 816).
|
|
- Coding standards: Clean ABAP. Methods below 40 statements. No global
|
|
variables. No comment that restates the code. Replace the prices and the
|
|
factors with named constants. Remove the repeated blocks. Use names that say
|
|
what the data and the methods mean.
|
|
- Out of scope: do not change the public interface of the class.
|
|
|
|
# 7. Acceptance
|
|
- The class is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the class.
|