Unkown Cls/Collection Holding An Event

Then, if you have a cTaxEngineFederal class, it might look like...
Code:
Private stg_ As Object
Private year_ As Long
Private fedTax_ As Currency
Private prvTax_ As Currency

Sub Init(Year As Long, Province As String)
    year_ = Year
    Set stg_ = GetTaxStrategy("Calc" & Province & "Tax")
End Sub

Sub CalcTotalTax()
    fedTax_ = CalcFedTax
    prvTax_ = stg_.Execute(fedTax_)
    
    MsgBox "Total Tax is " & fedTax_ + prvTax_
End Sub

Private Function CalcFedTax() As Currency
    ' returns federal tax
End Function
So this allows for runtime selection of an appropriate provincial tax calc strategy based on runtime data. And it keeps your code really tidy because each provincial strategy is discretely encapsulated in snap-in class expressly and independently developed and tested.
 
No, your first function does not create an instance. Somewhere you need to use the New keyword to create an instance. Your first function will raise an error because GetStrategy is not an object yet.
 

Users who are viewing this thread

Back
Top Bottom