Refactor strategy pattern to implement separation of concerns

- Update IModuleProcessor interface to accept targetBOMs collection instead of targetItemName string
- Remove filtering logic from strategy implementations (AppendOnly, CloneNew)
- Add LoadData method to mSpecAdditionManager for UI initialization
- Rename ExecuteAddition to ExecutePipeline with refined parameters
- Enhance test suite to simulate fine-grained UI selection behavior
- Enable precise row-level control by delegating filtering to UI layer

This refactoring achieves better separation of concerns where:
- Strategy layer focuses purely on execution logic
- UI layer handles selection and filtering
- Manager layer coordinates the pipeline flow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-03-19 15:04:24 +08:00
parent d17d7c5864
commit b73e39eeee
5 changed files with 92 additions and 109 deletions

View File

@@ -6,45 +6,53 @@
Option Explicit
' ------------------------------------------------------------------------------
' 过程名称: ExecuteAddition
' 过程名称: LoadData
' 过程功能: 供 UI 初始化时调用,加载总库数据
' ------------------------------------------------------------------------------
Public Function LoadData(ByVal ws As Worksheet) As Collection
Set LoadData = mBOMRepository.LoadAllBOMs(ws)
End Function
' ------------------------------------------------------------------------------
' 过程名称: ExecutePipeline
' 过程功能: 执行完整的新增规格流水线
' 参数说明:
' ws - 目标工作表对象
' targetItemName - 用户瞄准的物料名称 (如 "径向高压接头")
' paramName - 要修改的参数名 (如 "lcfw")
' newValue - 新增的规格值 (如 "M19")
' strategyType - UI选择的执行策略 (如 "APPEND" 或 "CLONE")
' ws - 目标工作表对象 (保存时需要)
' allBOMs - 内存中的总库集合
' targetBOMs - UI层过滤组装好的【精准目标集合】
' paramName - 要修改的参数名 (如 "lcfw")
' newValue - 新增的规格值 (如 "M19")
' strategyType - UI选择的执行策略 (如 "APPEND" 或 "CLONE")
' ------------------------------------------------------------------------------
Public Sub ExecuteAddition( _
Public Sub ExecutePipeline( _
ByVal ws As Worksheet, _
ByVal targetItemName As String, _
ByRef allBOMs As Collection, _
ByRef targetBOMs As Collection, _
ByVal paramName As String, _
ByVal newValue As String, _
ByVal strategyType As String)
' 如果没有选中任何目标,直接中断退出
If targetBOMs Is Nothing Then Exit Sub
If targetBOMs.count = 0 Then Exit Sub
Dim engine As cConditionEngine
Dim bomCollection As Collection
Dim processor As IModuleProcessor
' [步骤 1] 初始化核心手术刀引擎
Set engine = New cConditionEngine
' [步骤 2] 通过数据层将 Excel 读入内存变为对象集合
Set bomCollection = mBOMRepository.LoadAllBOMs(ws)
' [步骤 3] 从工厂获取用户指定的策略
' [步骤 2] 从工厂获取用户指定的策略
Set processor = mProcessorFactory.GetProcessor(strategyType)
' [步骤 4] 将数据集合与目标扔给策略对象执行
' 提示:所有的脏标记 (IsDirty) 会在这一步由对象自己触发记录
processor.ProcessSpec bomCollection, targetItemName, paramName, newValue, engine
' [步骤 3] 将总库、精准目标集合扔给策略对象执行
processor.ProcessSpec allBOMs, targetBOMs, paramName, newValue, engine
' [步骤 5] 将修改过的数据 (IsDirty=True) 批量写回 Excel
mBOMRepository.SaveAll ws, bomCollection
' [步骤 4] 将修改过的数据批量写回 Excel (只写 IsDirty=True 的对象)
mBOMRepository.SaveAll ws, allBOMs
' 释放资源 (VBA 虽然有垃圾回收,但良好习惯可以防止 Excel 卡死)
' 释放资源
Set processor = Nothing
Set bomCollection = Nothing
Set engine = Nothing
End Sub