Skip to content

Scope of a function being Static

Narik

Asked Apr 12, 2007, 3:46 AM EDT2 answers
Share
LinkedInX

Hi, I have declared all the functions in data access layer as static, so that i

need not instantiate a object to access those functions. Will there be any

problem in declaring all the functions as static? Also, will the commonly used

functions returns static value for concurrent users across the application?

Please clarify

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    there is no problem declaring all your functions as static, although not always the best design practice, especially if you plan on having multiple instances of a class.

    You just need to make sure that any member variables and properties used inside the methods are also static or it won't compile.
    0
  • 0
    Hi,

    more on Static methods:

    Static methods act more or less like global methods, in that you can invoke them without actually having an instance of the object at hand. The advantage of static methods over global, however, is that the name is scoped to the class in which it occurs, and thus you don't clutter up the global namespace with myriad function names. This can help manage highly complex programs, and the anme of the class acts very much like a namespace for the static methods within it.

    In addition, static methods may be passed instance members as parameters. Because they are scoped to the class, instead of being scoped globally, they have access to tye private members of the instances.

    Database programming with VB 2005, C# and SQL Server 2005
     
    0