Daniel Gee
Daniel Gee

Reputation: 438

Is it better to use a Class or Variables in the Signature of a Method?

I've often wondered. In terms of "best practice" when writing a Function, be it Local or in a Module / Class, it is better to use:

Public Function WhichIsBetter(ByVal tmpUser As String, _
                              tmpPassword As String) As Boolean
    'Do something
End Function

Or

Public Class User
    Public Property tmpUser As String
    Public Property tmpPassword As String
End Class

Public Function WhichIsBetter(ByVal tmpUser As User) As Boolean
     'Do something
End Function

Upvotes: 1

Views: 64

Answers (1)

Victor Zakharov
Victor Zakharov

Reputation: 26434

If no prior analysis has been done on code architecture, I would always start with ByVal tmpUser As String, tmpPassword As String signature and see how code evolves.

If you find yourself passing tmpUser and tmpPassword around very often, i.e. every function has a signature of these parameters + something else, chances are you need to be passing a User object instead. Consider using an object even more, if you happen to be adding the same parameter to multiple functions often.

Upvotes: 1

Related Questions