blob: 7b934b8a306bff3f79b0d3587d3e73f111477ab0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# Architecture Analysis and Refactoring Recommendations
## Current Architecture Issues
### Current Structure
```
CalendarManagerGUI
├── Contains business logic (EZ pauschal duration)
├── Duplicated keyword handling
├── Mixed UI and business concerns
└── Direct file operations
PredictionController
├── Too thin - delegates most logic
├── Duplicated keyword categorization
└── Missing validation/error handling
DateCalculator
├── Contains high-level orchestration
├── Business rule implementations
└── Mixed mathematical and business logic
CalendarManager
├── Contains business logic (correct_dates)
├── File I/O operations
└── Mixed data and business concerns
```
## Proposed Improved Architecture
### New Structure
```
CalendarManagerGUI (UI Layer)
├── Pure UI presentation
├── User interaction handling
└── Delegates business logic to services
PredictionController (Business Logic Layer)
├── Orchestrates prediction calculation
├── Handles business rules and validation
├── Manages event categorization
└── Coordinates between services
DateCalculator (Mathematical Layer)
├── Pure mathematical operations
├── Period manipulation algorithms
└── No business logic
CalendarManager (Data Layer)
├── CRUD operations for entries
├── Data validation and integrity
└── No business logic
EventTypeHandler (Business Rules Service)
├── Event type-specific business rules
├── Duration calculations per type
└── Event categorization logic
DateService (Utility Service)
├── Centralized date formatting
├── Date parsing and validation
└── Date conversion utilities
FileService (I/O Service)
├── File operations with error handling
├── Data serialization/deserialization
└── File validation
Config (Configuration)
├── Constants and configuration
├── Keyword definitions
└── Business rule parameters
```
## Specific Refactoring Tasks
### 1. Extract Configuration
- Move hardcoded keywords to `config.py`
- Centralize business rule parameters
- Define constants for durations and limits
### 2. Refactor DateCalculator
- Remove `calculate_prediction()` orchestration
- Keep only mathematical operations
- Remove business rule implementations
### 3. Enhance PredictionController
- Move orchestration logic from DateCalculator
- Add input validation and error handling
- Implement proper business logic coordination
### 4. Create EventTypeHandler
- Extract EZ pauschal duration logic from GUI
- Implement event type-specific business rules
- Handle event categorization logic
### 5. Create DateService
- Centralize date formatting logic
- Implement date parsing and validation
- Remove duplicated date conversion code
### 6. Create FileService
- Extract file operations from CalendarManager
- Add proper error handling
- Implement data serialization logic
### 7. Simplify CalendarManager
- Remove business logic from `correct_dates()`
- Keep only CRUD operations
- Focus on data integrity
### 8. Clean CalendarManagerGUI
- Remove business logic
- Delegate to appropriate services
- Focus on UI presentation only
## Benefits of Refactoring
1. **Separation of Concerns**: Each class has a single, clear responsibility
2. **Reduced Duplication**: Centralized configuration and utilities
3. **Better Testability**: Pure functions and isolated business logic
4. **Improved Maintainability**: Clear boundaries between layers
5. **Enhanced Reusability**: Services can be reused across components
6. **Better Error Handling**: Centralized error handling in services
|