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

@@ -1,16 +1,22 @@
' ==============================================================================
' 模块名称: IModuleProcessor
' 模块类别: 类模块 (用作接口 Interface)
' 模块职责: 定义统一的业务处理接口基于UI用户选择的物料名称进行精准处理
' 模块职责: 定义统一的业务处理接口。此时的策略层已完全解耦,不关心过滤逻辑。
' ==============================================================================
Option Explicit
' 方法名: ProcessSpec
' allBOMs: 包含所有物料信息的集合 (库里的所有数据)
' targetItemName: 要被处理的物料的名称字段 (瞄准镜)
' paramName: 参数名(如 lcfw)
' newValue: 新规格代码(如 M19)
' engine: 条件注入引擎实例
Public Sub ProcessSpec(ByRef allBOMs As Collection, ByVal targetItemName As String, ByVal paramName As String, ByVal newValue As String, ByRef engine As cConditionEngine)
' allBOMs: 总库集合 (主要用于克隆策略追加新行)
' targetBOMs: 由UI层(或中枢)精挑细选出来的目标行集合 (手术对象)
' paramName: 参数名(如 lcfw)
' newValue: 新规格代码(如 M19)
' engine: 条件注入引擎实例
Public Sub ProcessSpec( _
ByRef allBOMs As Collection, _
ByRef targetBOMs As Collection, _
ByVal paramName As String, _
ByVal newValue As String, _
ByRef engine As cConditionEngine)
'
End Sub

View File

@@ -1,28 +1,24 @@
' ==============================================================================
' 模块名称: cProcessor_AppendOnly
' 模块类别: 类模块
' 模块职责: 通用追加策略。适用于接头、封口片、机芯、盘止钉等。
' 逻辑描述: 遍历所有数据,凡是名称与目标匹配的变种,一律注入新条件
' 模块职责: 通用追加策略。
' 逻辑描述: 无脑遍历传入的 targetBOMs 集合,利用引擎进行条件追加
' ==============================================================================
Option Explicit
Implements IModuleProcessor
Private Sub IModuleProcessor_ProcessSpec( _
ByRef allBOMs As Collection, _
ByVal targetItemName As String, _
ByRef targetBOMs As Collection, _
ByVal paramName As String, _
ByVal newValue As String, _
ByRef engine As cConditionEngine)
Dim rowObj As cBOMRow
' 遍历整个库
For Each rowObj In allBOMs
' 只要名称完全匹配 (忽略大小写进行比对)
If StrComp(rowObj.ItemName, targetItemName, vbTextCompare) = 0 Then
'
rowObj.Condition = engine.InjectOr(rowObj.Condition, paramName, newValue)
End If
' UI targetBOMs
For Each rowObj In targetBOMs
rowObj.Condition = engine.InjectOr(rowObj.Condition, paramName, newValue)
Next rowObj
End Sub

View File

@@ -1,39 +1,29 @@
' ==============================================================================
' 模块名称: cProcessor_CloneNew
' 模块类别: 类模块
' 模块职责: 通用克隆新增策略。适用于弹性元件等需要完全独立成行的规格。
' 逻辑描述: 找到第一个匹配的母版行,克隆它并赋予纯粹的新规格条件
' 模块职责: 通用克隆新增策略。
' 逻辑描述: 遍历传入的 targetBOMs 母版集合,每遇到一个就克隆一行追加到总库,并赋新值
' ==============================================================================
Option Explicit
Implements IModuleProcessor
Private Sub IModuleProcessor_ProcessSpec( _
ByRef allBOMs As Collection, _
ByVal targetItemName As String, _
ByRef targetBOMs As Collection, _
ByVal paramName As String, _
ByVal newValue As String, _
ByRef engine As cConditionEngine)
Dim rowObj As cBOMRow
Dim templateRow As cBOMRow
Set templateRow = Nothing
Dim newRow As cBOMRow
' 1. 寻找母版 (找到同名的第一条记录即可)
For Each rowObj In allBOMs
If StrComp(rowObj.ItemName, targetItemName, vbTextCompare) = 0 Then
Set templateRow = rowObj
Exit For
End If
' 为 targetBOMs 里的每一个母版克隆出一个新对象
For Each rowObj In targetBOMs
' 调用数据访问层的克隆方法,自动加入 allBOMs 总集合
Set newRow = mBOMRepository.InsertNewBOMRow(allBOMs, rowObj)
' (lcfw=M19)
newRow.Condition = paramName & "=" & newValue
Next rowObj
' 2. 如果找到了母版,进行克隆
If Not templateRow Is Nothing Then
Dim newRow As cBOMRow
' 调用数据访问层的克隆方法,它会自动把新对象加入到 allBOMs 集合中
Set newRow = mBOMRepository.InsertNewBOMRow(allBOMs, templateRow)
' (lcfw=M19)
newRow.Condition = paramName & "=" & newValue
End If
End Sub