本文介绍了是一个不好的做法重载的方法时,返回diferent类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于这个例子:
Interface CustomersDao
Function Get(ByVal Id As Integer) As Customer
Function Get(ByVal Filter As Filter) As IList(Of Customer)
End Interface
Public Sub Main()
Dim Customer As Customer = CustomersDao.Get(4)
Dim Filter As New CustomersDao.Filter
Filter.Category = 2
Dim Customers As IList(Of Customer) = CustomersDao.Get(Filter)
End Sub
这是个不好的做法返回diferent类型相同的方法?
Is it a bad practice to return diferent types in the same method?
推荐答案
我会建议调用第二个 GETALL
。
现在,它并不明显,第二方法返回的集合。
你应该努力以确保您的类一样明显,尽可能不包含任何意想不到的惊喜。
Right now, it isn't obvious that the second method returns a collection.
You should strive to ensure that your classes are as obvious as possible and do not contain any unexpected surprises.
这篇关于是一个不好的做法重载的方法时,返回diferent类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!