This lab recreates and refactors Martin Fowler’s Site example to implement the Template Method Pattern.
- Built initial classes with duplicated "getBillableAmount()" logic.
- Extracted common base computation "getBaseAmount()".
- Converted "Site" to abstract class defining the template method.
- Subclasses now implement "getTypeSpecificCharge(base)" as hooks.
- Verified identical runtime results.
- Extract Method
- Make Abstract Class
- Pull Up (if applicable)
- Safe Delete / Reformat Code
Residential bill: 19.0
Industrial bill: 30.0
- JetBrains IDEA Refactoring Guide: https://www.jetbrains.com/help/idea/refactoring-source-code.html
- Fowler, M. Form Template Method Example: https://www.refactoring.com/catalog/formTemplateMethod.html