Common functions
Pete submit an interesting question on the mail list
Hi everyone
This probably a trivial question but here goes anyway.
Most web applications have a need for a "repository" of common functions, ie
user defined functions that are called from most pages.
In classic ASP this was accomplished by creating an include file with
numerous common functions and subs and then "including" that file in the
pages that needed access to any of those functions.
ASP.NET follows the OOP paradigm which involves a major brain shift when it
comes to programming web pages.
My question is how do we now provide those common functions and subs?
Do we have to create instances of classes and execute instance methods every
time or is it acceptable to create a "common" class with a whole bunch of
shared/static methods to be called as instance methods much the same wasy as
math.cos()
For instance, I might have a function that formats a date object in a
particular way and returns a string....
Function MyDateFormat(ByVal pDate As Date) As String
This function is called on most pages so what is the best place to put this
function? Is it necessary to instanciate an object just to perform this
function of would it be acceptable to use a shared class method in cases
such as this?
Thanks in advance
Pete H
It's true that in classic ASP, the way to use common routines is most of the time an Include at the top of each pages.
Now .Net offer more richer things, like user controls.
For common routines, the path I take is to have as much as possible the use of some helpers like the excellent Data Application Block, in complement of each of my projects.
And some shared methods that I setup in a class file or eventually I add a project to my web project to include some common resources there.
It would be interesting to know how other developers deal with common library, because it's not any more simple as it is with ASP.