我刚刚问了一个关于使用泛型(或多态)来避免重复代码的问题。我真的很想遵循DRY原则。你会使用Action委托来避免重复的代码吗?
所以我只是碰到了下面的代码...
Sub OutputDataToExcel()
OutputLine("Output DataBlocks", 1)
OutputDataBlocks()
OutputLine("")
OutputLine("Output Numbered Inventory", 1)
OutputNumberedInventory()
OutputLine("")
OutputLine("Output Item Summaries", 1)
OutputItemSummaries()
OutputLine("")
End Sub
我应该重写这段代码是使用Action委托如下...
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
我意识到这个问题主观。我只是想知道你如何虔诚地遵循DRY。你会这样做吗?
赛斯
中间图案的孔?它也可以称为甜甜圈模式吗? MMMMM ...甜甜圈。 – 2010-04-28 19:26:47