Subjective question...would you use the Action delegate to avoid duplication of code?

Posted by Seth Spearman on Stack Overflow See other posts from Stack Overflow or by Seth Spearman
Published on 2010-04-28T18:43:48Z Indexed on 2010/04/28 18:47 UTC
Read the original article Hit count: 796

Filed under:
|
|

Hello,
I just asked a question that helps about using generics (or polymorphism) to avoid duplication of code. I am really trying to follow the DRY principle.

So I just ran into the following code...

Sub OutputDataToExcel()

        OutputLine("Output DataBlocks", 1)
        OutputDataBlocks()
        OutputLine("")

        OutputLine("Output Numbered Inventory", 1)
        OutputNumberedInventory()
        OutputLine("")

        OutputLine("Output Item Summaries", 1)
        OutputItemSummaries()
        OutputLine("")

End Sub

Should I rewrite this code to be as follows using the Action delegate...

Sub OutputDataToExcel()
    OutputData("Output DataBlocks", New Action(AddressOf OutputDataBlocks))
    OutputData("Output Numbered Inventory", New Action(AddressOf OutputNumberedInventory))
    OutputData("Output Item Summaries", New Action(AddressOf OutputItemSummaries))
End Sub

Sub OutputData(ByVal outputDescription As String, ByVal outputType As Action)
    OutputLine(outputDescription, 1)
    outputType()
    OutputLine("")
End Sub

I realize this question is subjective. I am just wondering about how religiously you follow DRY. Would you do this?

Seth

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about action