Refactoring
Refactoring is technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
You may want to modify existing workflow steps to reflect changing business needs in due course. For example, you may want to:
- Rename a workflow step so that it reflects its business intent better.
- Add or remove parameters to workflows.
Refactoring is a powerful concept that helps you maintain your tests suites better.
Rephrase refactoring
Rephrase refactoring
allows you to rename workflows and change the parameters that it
accepts.
Consider the Workflow below:
Transfer
- transfer "1000" from account "1234" to "2345"
- destination account is credited
- Check destination account is credited to make it more readable.
- Check destination account "2345" is credited "1000" so that you can reuse the workflow step in other scenarios as it now accepts parameters.
Extract Concept
"Extract Concept"
makes it possible to merge two or more related statements to create a
more meaningful abstraction.
For example,
Create Order
- Create an order "O" as price "23" quantity "50"
- Submit order "O"
Create Order
- Submit an order "O" as price "23" quantity "50"
Inferring parameters in extracted code
Twist allows you to type in parameters in the extracted concept. You could specify existing or new parameters.
- If you specify a new parameter, Twist introduces a new parameter in your extracted concept
-
If you specify a parameter that is present in any of the extracted
workflow steps, Twist parameterizes all occurrences
of that parameter in the underlying code.
For example,
Create Order
- Create an order "O" as price "23" quantity "50"
- Submit order "O"
- Submit an order "O" as price "23" quantity "50" then the underlying code is refactored as follows:
public void submitAnOrderAsPriceQuantity(String string1, int price, int quantity) {
createAnOrderAsPriceQuantity(string1, price, quantity);
submitOrder(string1);
}