Refactor: Replace Abstract Factory with Strategy Pattern - #19
Merged
Merged
Conversation
, #11) This commit completes a major refactoring of the analysis module, replacing the Abstract Factory pattern with a simpler Strategy Pattern and removing significant amounts of duplicate and broken code. ## Changes Made ### Issue #9: Implement Strategy Pattern - Added new `Analysis` class with unified interface for all chart types - Implemented strategy methods: `_calculate_xbar()`, `_calculate_s()`, `_calculate_imr()`, `_calculate_r()` - Updated `perform_analysis()` to use new unified Analysis class - Removed old factory classes: - AbstractFactory - AnalysisFactory - AbstractAnalysis - Xbar, Sbar, IMR, R concrete classes - Total: 475 lines of factory pattern code removed ### Issue #10: Fix Broken Property Methods - Removed AbstractAnalysisSpecification ABC (unused, single implementation) - Removed AbstractAnalysisDataSet ABC (unused, single implementation) - Removed 13 broken property methods that referenced self.attribute without returning values (critical bug) - Removed ABC imports no longer needed ### Issue #11: Remove Duplicate Calculation Functions - Removed 4 standalone calculation functions made obsolete by Analysis class: - calculate_statistics_Imr() (87 lines) - calculate_statistics_R() (82 lines) - calculate_statistics_S() (40 lines) - calculate_statistics_XbarS() (111 lines) - Total: 320 lines of duplicate code removed ## Impact - Net reduction: 405 lines (~36% smaller file) - Code complexity: Significantly reduced through Strategy Pattern - Maintainability: Single source of truth for each analysis type - All 27 tests passing ✓ ## Technical Details - Strategy Pattern uses dictionary dispatch for analysis type selection - Backward compatible - perform_analysis() API unchanged - No breaking changes to public interface 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
21 tasks
cnicholas
added a commit
that referenced
this pull request
Sep 1, 2026
, #11) (#19) This commit completes a major refactoring of the analysis module, replacing the Abstract Factory pattern with a simpler Strategy Pattern and removing significant amounts of duplicate and broken code. ## Changes Made ### Issue #9: Implement Strategy Pattern - Added new `Analysis` class with unified interface for all chart types - Implemented strategy methods: `_calculate_xbar()`, `_calculate_s()`, `_calculate_imr()`, `_calculate_r()` - Updated `perform_analysis()` to use new unified Analysis class - Removed old factory classes: - AbstractFactory - AnalysisFactory - AbstractAnalysis - Xbar, Sbar, IMR, R concrete classes - Total: 475 lines of factory pattern code removed ### Issue #10: Fix Broken Property Methods - Removed AbstractAnalysisSpecification ABC (unused, single implementation) - Removed AbstractAnalysisDataSet ABC (unused, single implementation) - Removed 13 broken property methods that referenced self.attribute without returning values (critical bug) - Removed ABC imports no longer needed ### Issue #11: Remove Duplicate Calculation Functions - Removed 4 standalone calculation functions made obsolete by Analysis class: - calculate_statistics_Imr() (87 lines) - calculate_statistics_R() (82 lines) - calculate_statistics_S() (40 lines) - calculate_statistics_XbarS() (111 lines) - Total: 320 lines of duplicate code removed ## Impact - Net reduction: 405 lines (~36% smaller file) - Code complexity: Significantly reduced through Strategy Pattern - Maintainability: Single source of truth for each analysis type - All 27 tests passing ✓ ## Technical Details - Strategy Pattern uses dictionary dispatch for analysis type selection - Backward compatible - perform_analysis() API unchanged - No breaking changes to public interface 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR completes a major refactoring of the analysis module, addressing Issues #9, #10, and #11. It replaces the Abstract Factory pattern with a simpler Strategy Pattern and removes ~800 lines of duplicate, broken, and unnecessary code.
Changes
✨ Issue #9: Strategy Pattern Implementation
Analysisclass with unified interface for all chart types (Xbar, S, Imr, R)_calculate_xbar(),_calculate_s(),_calculate_imr(),_calculate_r())perform_analysis()to use new unified classAbstractFactoryclassAnalysisFactoryconcrete factoryAbstractAnalysisbase classXbar,Sbar,IMR,Rconcrete analysis classes🐛 Issue #10: Fix Critical Bugs in Property Methods
None)AnalysisSpecification:data_prep_output_cols(),analysis_output_cols(),sort_cols(),has_grouping(),grouping_cols(),has_time(),requires_sort()AnalysisDataSet:sampling_design_state(),raw_dataset(),analysis_dataset(),statistics(),interactions(),effects()AbstractAnalysisSpecification(single implementation, no polymorphism benefit)AbstractAnalysisDataSet(single implementation, no polymorphism benefit)🧹 Issue #11: Remove Duplicate Calculation Functions
Analysisclass:calculate_statistics_Imr()— 87 linescalculate_statistics_R()— 82 linescalculate_statistics_S()— 40 linescalculate_statistics_XbarS()— 111 linesImpact
Code Quality Metrics
Benefits
perform_analysis()) remains unchangedTesting
pytest tests/ -v # ============================== 27 passed in 0.77s ==============================All existing tests pass without modification, confirming backward compatibility.
Technical Details
Strategy Pattern Implementation
Backward Compatibility
The public interface remains unchanged:
Checklist
Related Issues
Closes #9
Closes #10
Closes #11
🤖 Generated with Claude Code