The Builder Pattern in VBA
Construct complex workbook rituals step by step, separating the assembly from the final dark manifestation.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Builder
ARCANUM SCHOOL: Conjuration // Spreadsheet Necromancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// VBA PATTERN //
' Interface: IReportBuilder (Class Module)
Public Sub BindDataSoul()
End Sub
Public Sub FormatBones()
End Sub
Public Sub CastFormulas()
End Sub
Public Function GetResult() As Worksheet
End Function
' Class: NecromanticReportBuilder (Class Module)
Implements IReportBuilder
Private pSheet As Worksheet
Private Sub Class_Initialize()
Set pSheet = ThisWorkbook.Sheets.Add
pSheet.Name = "Dark_Manifest_" & Format(Now, "hhmmss")
End Sub
Private Sub IReportBuilder_BindDataSoul()
pSheet.Range("A1").Value = "Soul Fragments"
End Sub
Private Sub IReportBuilder_FormatBones()
pSheet.Range("A1").Interior.Color = RGB(0, 0, 0)
pSheet.Range("A1").Font.Color = RGB(255, 0, 0)
End Sub
Private Sub IReportBuilder_CastFormulas()
pSheet.Range("A2").Formula = "=SUM(B:B) * -1"
End Sub
Private Function IReportBuilder_GetResult() As Worksheet
Set IReportBuilder_GetResult = pSheet
End Function
' Director (Standard Module)
Public Function ConstructReport(builder As IReportBuilder) As Worksheet
builder.BindDataSoul
builder.FormatBones
builder.CastFormulas
Set ConstructReport = builder.GetResult()
End Function
The Builder: Assembling the Flesh Golem
When a report requires intricate formatting, ethereal connections to external databases, and the weaving of complex array formulas, constructing it in a single monstrous function is madness. The Builder pattern allows a spreadsheet necromancer to assemble complex artifacts step by step.
The Director dictates the order of the ritual, while the Builder implements the dark details. Whether you are building a NecromanticReportBuilder or a CorporateFinancialBuilder, the Director’s invocation remains unchanged. The resulting golem is perfectly formed, its bones aligned and its formulas pulsating with dark energy.
Runic Tags:
#vba
#builder
#creational
#spreadsheet-necromancy