54 lines
2.2 KiB
Markdown
54 lines
2.2 KiB
Markdown
# 1. Goal
|
|
Refactor the class {{P}}CLIMB_PRICER in package $TMP. The class calculates the
|
|
price of a climbing session at a climbing centre. The booking program of the
|
|
centre calls the class for each session. The class is correct today, but the
|
|
code is hard to read and hard to change. Make the code clean and easy to
|
|
change. The behavior must stay the same.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- The class {{P}}CLIMB_PRICER exists in package $TMP. It is active.
|
|
- The booking program calls the method PRICE and then reads the components of
|
|
the result structure.
|
|
- No user reports a wrong price. All prices are correct.
|
|
- The implementation is one long method with deep nesting and many literal
|
|
values. A change to one rate is risky.
|
|
|
|
# 4. Contract
|
|
- Refactor the class {{P}}CLIMB_PRICER in package $TMP. The name stays the
|
|
same.
|
|
- The class is public and final. It has a public constructor without
|
|
parameters.
|
|
- The public interface must not change. It is:
|
|
- TYPES ty_entry TYPE c LENGTH 1.
|
|
- TYPES ty_amount TYPE p LENGTH 8 DECIMALS 2.
|
|
- TYPES ty_session with the components entry_type TYPE ty_entry,
|
|
hours TYPE i, climbers TYPE i, equipment TYPE abap_bool,
|
|
member TYPE abap_bool and visits TYPE i.
|
|
- TYPES ty_result with the components base TYPE ty_amount,
|
|
surcharge TYPE ty_amount, discount TYPE ty_amount, total TYPE ty_amount
|
|
and message TYPE string.
|
|
- METHODS price IMPORTING is_session TYPE ty_session
|
|
RETURNING VALUE(rs_result) TYPE ty_result.
|
|
- Do not add other public methods or public types.
|
|
|
|
# 5. Business rules
|
|
The legacy code contains all the rules. Read the code of {{P}}CLIMB_PRICER
|
|
before you change it. Each input must give the same result as the legacy code.
|
|
Keep each limit, each rate, each surcharge, each discount and each message
|
|
text.
|
|
|
|
# 6. Constraints
|
|
- Release target: 8.16.
|
|
- Coding standards: Clean ABAP. Methods below 40 statements. No global
|
|
variables. No magic numbers. No comment that restates the code.
|
|
- Out of scope: do not change the public interface of {{P}}CLIMB_PRICER. Do not
|
|
create other objects.
|
|
|
|
# 7. Acceptance
|
|
- The class is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the class.
|