QN: Global functions?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngarchitecture' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Lamprecht, Jan
-- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones <Click here to reveal e-mail address> --

What is the best way in ASP.NET of handling functions which one previously
put into
include files and had available globally? I am thinking of custom code which
performs
simple functions which are often needed and which is not suitable for a
class since a
single function is more than adequate.

Should one create a single "class" for all these functions to then be
methods of?
Or are there other alternatives?

___________________________________________________________________________________________________

The views expressed in this email are, unless otherwise stated, those of the author and not those
of the FirstRand Banking Group or its management. The information in this e-mail is confidential
and is intended solely for the addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, distribution or any action taken or
omitted in reliance on this, is prohibited and may be unlawful.
Whilst all reasonable steps are taken to ensure the accuracy and integrity of information and data
transmitted electronically and to preserve the confidentiality thereof, no liability or
responsibility whatsoever is accepted if information or data is, for whatever reason, corrupted
or does not reach its intended destination.

________________________________

Reply to this message...
 
    
Dan Wahlin
Everything is ultimately a class in .NET which makes your choice a
little easier. :) I generally take the methods and put them into a
specific class that is used to encapsulate them with other related
methods. For example, methods specific to a user may go in a User.cs or
User.vb file. I then instantiate and use that class as appropriate in
the ASP.NET app.

If you throw everything into a more generic ("global") class I think
you'll discover that it becomes hard to find things as the class grows
in size. By separating things out by function into smaller classes
things are more manageable and re-useable. All of this gets into good
object-oriented design techniques.

After you compile the class(s) just throw it into the /bin directory and
off you go. If several other applications will use it you can look at
putting it into the Global Assembly Cache (GAC) so that each /bin
directory doesn't have to have a copy.

HTH,
Dan Wahlin

Wahlin Consulting LLC
Microsoft MVP - ASP.NET
http://www.XMLforASP.Net: #1 ASP.NET XML Resource
XML for ASP.NET Developers by Dan Wahlin in bookstores everywhere!

-----Original Message-----
From: Lamprecht, Jan [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 6:04 AM
To: aspngarchitecture
Subject: [aspngarchitecture] QN: Global functions?

-- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --

What is the best way in ASP.NET of handling functions which one
previously
put into
include files and had available globally? I am thinking of custom code
which
performs
simple functions which are often needed and which is not suitable for a
class since a
single function is more than adequate.

Should one create a single "class" for all these functions to then be
methods of?
Or are there other alternatives?

________________________________________________________________________
___________________________

The views expressed in this email are, unless otherwise stated, those of
the author and not those
of the FirstRand Banking Group or its management. The information in
this e-mail is confidential
and is intended solely for the addressee. Access to this e-mail by
anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or
omitted in reliance on this, is prohibited and may be unlawful.
Whilst all reasonable steps are taken to ensure the accuracy and
integrity of information and data
transmitted electronically and to preserve the confidentiality thereof,
no liability or
responsibility whatsoever is accepted if information or data is, for
whatever reason, corrupted
or does not reach its intended destination.

________________________________
| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
dave wanta (VIP)
Typically you will create a "Utility" class, that is used site wide, under
the same namespace as the website.

Depending upon what these functions do, you may want to make them shared
(VB) or static (C#) which will remove the need for creating an instance of
the object.'

hth,
Dave
----- Original Message -----
From: "Lamprecht, Jan" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Thursday, July 11, 2002 8:03 AM
Subject: [aspngarchitecture] QN: Global functions?

> -- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --
[Original message clipped]

_______________________
[Original message clipped]

Reply to this message...
 
    
Daniel Wilson
I've used a few different approaches.
One is to create a Utility class with a slew of Static Methods which
correspond the functions I would have placed in an include file and through
it in the binn directly for my apps. However, lately I've stopped doing
that in such an all encompassing way. One could create specialized Utility
classes that deal with common specific areas of the problem domain. For
instances UtilityUser, UtilityProduct, and etc. In most cases I've found
that I can usually fit these methods in a good base class for say, User or
Product with these utility functions grouped in there own namespace. i.e
User.Utilities

HTH,
Daniel Wilson

-----Original Message-----
From: Lamprecht, Jan [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 9:04 AM
To: aspngarchitecture
Subject: [aspngarchitecture] QN: Global functions?

-- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --

What is the best way in ASP.NET of handling functions which one previously
put into include files and had available globally? I am thinking of custom
code which performs simple functions which are often needed and which is not
suitable for a class since a single function is more than adequate.

Should one create a single "class" for all these functions to then be
methods of? Or are there other alternatives?

____________________________________________________________________________
_______________________

The views expressed in this email are, unless otherwise stated, those of the
author and not those of the FirstRand Banking Group or its management. The
information in this e-mail is confidential and is intended solely for the
addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, distribution
or any action taken or
omitted in reliance on this, is prohibited and may be unlawful. Whilst all
reasonable steps are taken to ensure the accuracy and integrity of
information and data
transmitted electronically and to preserve the confidentiality thereof, no
liability or
responsibility whatsoever is accepted if information or data is, for
whatever reason, corrupted
or does not reach its intended destination.

________________________________
| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Domina Tang

With VB.Net, you can put functions in Module to act as global functions. But
I am not sure the disadvantage and advantage between putting functions in
"global" class and in module.

Thanks
Domina

-----Original Message-----
From: Dan Wahlin [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 12:35 PM
To: aspngarchitecture
Subject: [aspngarchitecture] RE: QN: Global functions?

Everything is ultimately a class in .NET which makes your choice a
little easier. :) I generally take the methods and put them into a
specific class that is used to encapsulate them with other related
methods. For example, methods specific to a user may go in a User.cs or
User.vb file. I then instantiate and use that class as appropriate in
the ASP.NET app.

If you throw everything into a more generic ("global") class I think
you'll discover that it becomes hard to find things as the class grows
in size. By separating things out by function into smaller classes
things are more manageable and re-useable. All of this gets into good
object-oriented design techniques.

After you compile the class(s) just throw it into the /bin directory and
off you go. If several other applications will use it you can look at
putting it into the Global Assembly Cache (GAC) so that each /bin
directory doesn't have to have a copy.

HTH,
Dan Wahlin

Wahlin Consulting LLC
Microsoft MVP - ASP.NET
http://www.XMLforASP.Net: #1 ASP.NET XML Resource
XML for ASP.NET Developers by Dan Wahlin in bookstores everywhere!

-----Original Message-----
From: Lamprecht, Jan [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 6:04 AM
To: aspngarchitecture
Subject: [aspngarchitecture] QN: Global functions?

-- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --

What is the best way in ASP.NET of handling functions which one
previously
put into
include files and had available globally? I am thinking of custom code
which
performs
simple functions which are often needed and which is not suitable for a
class since a
single function is more than adequate.

Should one create a single "class" for all these functions to then be
methods of?
Or are there other alternatives?

________________________________________________________________________
___________________________

The views expressed in this email are, unless otherwise stated, those of
the author and not those
of the FirstRand Banking Group or its management. The information in
this e-mail is confidential
and is intended solely for the addressee. Access to this e-mail by
anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or
omitted in reliance on this, is prohibited and may be unlawful.
Whilst all reasonable steps are taken to ensure the accuracy and
integrity of information and data
transmitted electronically and to preserve the confidentiality thereof,
no liability or
responsibility whatsoever is accepted if information or data is, for
whatever reason, corrupted
or does not reach its intended destination.

________________________________
| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Rick Elbers (VIP)
Hello Jan,

In the OO world static functions are the preffered
choice over global procedures.
In vb.net they can be implemented by methods SHARED
(which btw has a long history in Basic)

Rick Elbers

----- Original Message -----
From: "Lamprecht, Jan" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Thursday, July 11, 2002 3:03 PM
Subject: [aspngarchitecture] QN: Global functions?

> -- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --
[Original message clipped]

_______________________
[Original message clipped]

Reply to this message...
 
    
Russ McClelland
In a word: vomitorious.

You should *never* create a catch all Utility class. This shows that
you haven't fully analyzed your problem domain and identified all the
classes. Calculations belong on Number classes, string formatting
functions belong on obejcts that contain the strings, etc. I have never
seen a Utility class that didn't have methods that shouldn't have been
put on other classes...

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, July 11, 2002 11:28 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: QN: Global functions?

Typically you will create a "Utility" class, that is used site wide,
under the same namespace as the website.

Depending upon what these functions do, you may want to make them shared
(VB) or static (C#) which will remove the need for creating an instance
of the object.'

hth,
Dave
----- Original Message -----
From: "Lamprecht, Jan" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Thursday, July 11, 2002 8:03 AM
Subject: [aspngarchitecture] QN: Global functions?

> -- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --
[Original message clipped]

____
_______________________
[Original message clipped]

| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Damon Allison
I'm of the same mindset as Russ here, be careful with anything
'utility-like' because that will turn into a catch-all class and probably
will not be factored correctly. If you look at the .NET libraries, there
aren't too many utility classes I can think of (that do string formatting,
parsing, etc.. in the same class like you are proposing with utility)..

I'm not a fan of the vb keyword 'module' (among others). It seems to be
kept for backward compatibility and does not serve a purpose in OO (and thus
VB.net). I have never used a module and have been fine to this point. I
think purely in terms of OO design and think modules tend to distort what is
really happening. Behind the scenes, vbc will create a sealed class and
each function/sub in the module is static (shared in vb, i think). Why not
create a sealed class with static functions?

I apologize for the long winded rant here. To answer your question: " What
is the best way in ASP.NET of handling functions which one previously put
into include files and had available globally? " You might want to think in
terms creating an object library. Chances are these 'global' (YUK)
functions can be grouped logically into classes. It will be easier to
version and maintain later. Basically, what Russ said!

Best of luck, Damon

----- Original Message -----
From: "Russ McClelland" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Thursday, July 11, 2002 8:26 PM
Subject: [aspngarchitecture] Re: QN: Global functions?

In a word: vomitorious.

You should *never* create a catch all Utility class. This shows that
you haven't fully analyzed your problem domain and identified all the
classes. Calculations belong on Number classes, string formatting
functions belong on obejcts that contain the strings, etc. I have never
seen a Utility class that didn't have methods that shouldn't have been
put on other classes...

-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 11, 2002 11:28 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: QN: Global functions?

Typically you will create a "Utility" class, that is used site wide,
under the same namespace as the website.

Depending upon what these functions do, you may want to make them shared
(VB) or static (C#) which will remove the need for creating an instance
of the object.'

hth,
Dave
----- Original Message -----
From: "Lamprecht, Jan" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Thursday, July 11, 2002 8:03 AM
Subject: [aspngarchitecture] QN: Global functions?

> -- Moved from [aspngfreeforall] to [aspngarchitecture] by Marcie Jones
<Click here to reveal e-mail address> --
[Original message clipped]

____
_______________________
[Original message clipped]

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Rick Elbers (VIP)
Dear Damon and Russ,

1. The concept module or building block is a very old concept
which has a very well established place in classic OO literature
( you might consider READING Jacobson).
Its the unit of reuse. Also you might look into unit testing as it is
currently widely propagated

2. The concept of *never* is something I usually do not come across
in OO design, and the same holds for the concept of *always*. Those
concepts you might need the first few years as guide, but later on you
will see
that its not so easy to distinguish between designs. In practice there
are
a lot of ways to implement a singleton. Most of them can be considered
functionally equal imho. And indeed most (huge) systems have quit a few
of them.
That alone is reason enough to consider the possibility if you do not
consider
yourself much more brilliant then other people. What is possible is to
deliver
some guidelines when to use and when rather not to use
class_implementations.

3. The real question might be something like:
When to use singleton solutions and when to use objects( instances )
solutions ?

I can't give anything more then some interval as a starter. It does not
seem very
useful to implement file_system functions on a lot of classes. Since it
is behavior
of the environment of your application( the OS) of which there is only 1
at a certain
point in time it does not vary along with anything in your
application( normally).
In fact very low level abstraction will make OS transparent for your
application.
So its possible to make every class that uses this file_system inherit
some base_class_singleton,
but then you have run_time inflexibility already and also how many
classes would
you consider to be a " file_system" ?. When we use instance delegation
you can
also ask yourself if some object "has a " filesystem ?. Its more the OS
who has
that don't we agree ? Therefore I think file_system is a good utility
class.

On the other hand you can consider the problem to find some shortest
path route
between two places in a network. Somebody might want to implement a
global entry
point in that module in some kind of "route_finder_manager". This I
consider not
so useful because every route has to know how to find a shortest_path.
Its really something
that a route "has", although there might be different implementations
even for different
routes/ or costs. So the gain of the manager singleton is nihil and the
semantic distortation
of the manager "facade" I consider hiding the object responsibilities
which should have
been public.

Rick Elbers

----- Original Message -----
From: "Damon Allison" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Friday, July 12, 2002 5:05 AM
Subject: [aspngarchitecture] Re: QN: Global functions?

[Original message clipped]

Reply to this message...
 
    
Damon Allison
Hi Rick, <and group>

Thanks for the comments. I haven't dusted off jacobsen in a while. ahh the
memories. :-)

[Original message clipped]

Do you mean the 'class' is the unit for reuse? Modules turn into classes
in IL. The module has no meaning to the CLR at the type (class) level. The
.module keyword is used in the manifest (i believe it describes the .dll
file), maybe you meant that as the unit of reuse?

For the original question of taking asp functions (presumably a set of
widely different purposes) and converting them to .net... If you want to
group them in a module or a class, I guess it really doesn't matter - as
long as they are grouped correctly. They will both get compiled into a
class eventually, its the grouping of like functions that becomes important.
Having one module or class that does everything is a poor design.

If 'module' is a necessary keyword for OO concepts, why do languages like C#
or java not implement them?

Thanks!

Damon

----- Original Message -----
From: "Rick Elbers" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Friday, July 12, 2002 2:52 AM
Subject: [aspngarchitecture] Re: QN: Global functions?

[Original message clipped]

Reply to this message...
 
    
Rick Elbers (VIP)
Hi Damon,
Module is not a keyword, its worse: a keyconcept:-)
Rick

----- Original Message -----
From: "Damon Allison" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Friday, July 12, 2002 2:54 PM
Subject: [aspngarchitecture] Re: QN: Global functions?

[Original message clipped]

Reply to this message...
 
 




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com