Sprout and wrap techniques help safely add or modify functionality in existing code by introducing new methods, classes, or wrappers. These approaches minimize risk, preserve legacy behavior, and improve testability. This course covers both techniques for refactoring and expanding Scala code.
Overview
Syllabus
- Unit 1: Sprout Method - Reducing Risk of Adding New Features
- Sprouting a New Order Processing Method
- Testing Order Processing with Surcharges
- Testing Empty Orders with Surcharges
- Testing Negative Surcharges with Parametrized Tests
- Testing Order Processing with Surcharges
- Unit 2: Sprout Method - When a Method Does Too Much
- Extract Customer Lookup Method
- Extract Order Calculation Logic
- Extract Payment Logic for Better Code
- Extract Order Status Update Method
- Extract Email Confirmation Method
- Unit 3: Wrap Method - Safely Adding New Behaviors to Existing Code
- Extract Method Refactoring Pattern
- Adding Fraud Detection to OrderProcessor
- Using the New Dependency to Prevent Fraud
- Testing Fraud Detection with Mocks
- Testing Order Processing Without Fraud
- Unit 4: Sprout Class - When Classes Do Too Much
- Creating a Metrics Collector Class
- Order Metrics Collection System
- Adding Metrics Collector Dependency
- Metrics Collection Refactoring
- Unit 5: Sprout Class - When New Shouldn't Affect Old
- Enhancing Order System with Customer Features
- Loyalty Rewards for Valued Customers
- Building a Discount Order Processor
- Discount Processing for Loyal Customers
- Unit 6: Wrap Class - Expanding Whole Class Behavior
- Create a Trait for Order Processing
- Creating the new Order Processor that Logs Events
- Adding Logs to Order Processing
- Complete the Order Cancellation Logger