質問

Let's say for instance I have a class set up as such:

Class Foo
    Private instanceVariable As Integer = 2

    Public Shared Function Bar(ByVal localVariable as Integer) As Integer
        Return localVariable * 2
    End Function

    Public Function Bar() As Integer
        Return Bar(instanceVariable)
    End Function
End Class

I have a, hopefully, relatively simple question/s. Is this good design or is this frowned upon? Why?

EDIT:
After some of the comments I'm refining what I'm asking.

Is this inherently bad? Or is it perfectly fine, but as with everything it can be misused?

役に立ちましたか?

解決

In itself, the practice is not bad. It's the code's intention that will determine whether or not your design choice is appropriate. When you think about it, that applies to pretty much every known coding patterns. You might as well have asked if using generic types or multithreading are good practices or not, the answer would've been the same.

There are non-static classes within the .NET framework that does use shared methods and within their own context it makes perfect sense. This alone should allow you to think it's not a bad practice at all.

All you have to do is simply questioning yourself about what you are trying to do and if whether it makes sense or not to do it in a static context.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top