3

I've run into a legacy project set up as a .NET Web Site Project (yes, I know...) and I see lots of classes like these:

Public Class ControlStuff

    Public Shared Sub DoStuff(ByVal key as String)
       ...
    End Sub

    Public Shared Function IsAvailableStuff(ByVal key as String) as Boolean
        ...
        Return stuff
    End Function
End Class

Since it's being used in a web application, does this pose a problem when two or more visitors force the execution of any of these Sub or Function and values from one of them are returned to the other(s)? or does IIS isolate them?

jonayreyes
  • 538
  • 1
  • 10
  • 27
  • 1
    Depends on what the function do. If they have their own variables and don't try to read/write shared resource then it should be ok. – the_lotus Jan 28 '15 at 16:21
  • What the_lotus said. For instance, a sub that writes to a file could run into file locking issues if run at the same time by multiple users (or by the same user). It depends on the situation and the code as to whether it's an issue. Just having shared methods isn't really an issue, depends on what they do. – b.pell Jan 28 '15 at 16:30
  • They only retrieve a single record from the database, usually appending sqlparameters based on Session variables. Others do simple Redirects to other webforms, things like that – jonayreyes Jan 28 '15 at 16:40
  • If that's all it's doing I don't see any issues with it in regards to it being in a static class. In terms of the DB, whether the call is made here or elsewhere in the project shouldn't matter (whether you call it in a static class, or a code behind or a controller, etc.). If you have locking issues with the DB because of pending transactions then that's something you'd have to handle in all of these places (again the static class not really being the issue). – b.pell Jan 28 '15 at 17:33
  • Thanks. But what about a class that has no properties, no data? it's just a bag for holding a bunch of methods. Can this be seen as an allowed or good practise OOP? – jonayreyes Jan 29 '15 at 08:57

1 Answers1

-1

I often com e across it. It's often used to make functions/subs that work all over the current project but you do not want to be in your standardtoolbox. I do not see a problem doing this (OOP wise).Objects do not have to have properties or methods and can have shared methods. Overall this practice makes life a bit easier by separating your project-only routines from your standardtoolbox.

Ton
  • 316
  • 2
  • 12