473,411 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Shared/Static methods & functions

MPF
When designing a n-tier architecture, what is the preferred method/function
accessibility?
<Specifically for asp.net apps>
A private constructor and shared/static methods & functions?
A public constructor and non-shared/static methods & functions?

Are there any drawbacks with regards to performance with either model?

Thanks,

Morgan


Nov 16 '05 #1
4 1937
The answer depends on what you are modeling with the design.

If you are modeling a Customer, 99.9% of the time you'll want to create instances
of the Customer class with a public ctor and invoke non-static methods on
the instance.

If you are creating a 'helper' class with generic data access functions you
want a shortcut to, then static methods can help achieve that design.

In general, think of the design and how you'll use the abstractions before
applying syntax to the design.

In general (again), the perf differences are negligible, but the static /
shared keywords carry a lot of weight and can add complexity.

Some more info:

http://msdn.microsoft.com/msdnmag/is...T/default.aspx
http://odetocode.com/Articles/313.aspx
http://odetocode.com/Articles/314.aspx

I hope this helps out,

--
Scott
http://www.OdeToCode.com/blogs/scott/
When designing a n-tier architecture, what is the preferred
method/function
accessibility?
<Specifically for asp.net apps>
A private constructor and shared/static methods & functions?
A public constructor and non-shared/static methods & functions?
Are there any drawbacks with regards to performance with either model?

Thanks,

Morgan

Nov 16 '05 #2
Hi,
A private constructor and shared/static methods & functions?
This approach (and the Singleton design pattern) are good for objects who
should have only one instance. These include various facades, utility
classes etc.
A public constructor and non-shared/static methods & functions?
This approach is recommended for classes representing business entities,
where there can be an arbitrary number of instances.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"MPF" <ab**@senditon.com> wrote in message
news:OP****************@tk2msftngp13.phx.gbl... When designing a n-tier architecture, what is the preferred
method/function accessibility?
<Specifically for asp.net apps>
A private constructor and shared/static methods & functions?
A public constructor and non-shared/static methods & functions?

Are there any drawbacks with regards to performance with either model?

Thanks,

Morgan


Nov 16 '05 #3
Thanks for the clarification.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2******************@tk2msftngp13.phx.gbl...
Hi,
A private constructor and shared/static methods & functions?


This approach (and the Singleton design pattern) are good for objects who
should have only one instance. These include various facades, utility
classes etc.
A public constructor and non-shared/static methods & functions?


This approach is recommended for classes representing business entities,
where there can be an arbitrary number of instances.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"MPF" <ab**@senditon.com> wrote in message
news:OP****************@tk2msftngp13.phx.gbl...
When designing a n-tier architecture, what is the preferred
method/function accessibility?
<Specifically for asp.net apps>
A private constructor and shared/static methods & functions?
A public constructor and non-shared/static methods & functions?

Are there any drawbacks with regards to performance with either model?

Thanks,

Morgan

Nov 16 '05 #4
MPF
Thanks for the additional info, Scott.
Thanks for the links as well.

"Scott Allen" <sc***@nospam.OdeToCode.com> wrote in message
news:46*********************@msnews.microsoft.com. ..
The answer depends on what you are modeling with the design.
If you are modeling a Customer, 99.9% of the time you'll want to create
instances of the Customer class with a public ctor and invoke non-static
methods on the instance.
If you are creating a 'helper' class with generic data access functions
you want a shortcut to, then static methods can help achieve that design.
In general, think of the design and how you'll use the abstractions before
applying syntax to the design.
In general (again), the perf differences are negligible, but the static /
shared keywords carry a lot of weight and can add complexity.
Some more info:

http://msdn.microsoft.com/msdnmag/is...T/default.aspx
http://odetocode.com/Articles/313.aspx
http://odetocode.com/Articles/314.aspx

I hope this helps out,
--
Scott
http://www.OdeToCode.com/blogs/scott/
When designing a n-tier architecture, what is the preferred
method/function
accessibility?
<Specifically for asp.net apps>
A private constructor and shared/static methods & functions?
A public constructor and non-shared/static methods & functions?
Are there any drawbacks with regards to performance with either model?

Thanks,

Morgan


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. What are the implications, (in terms of memory, application footprint, resource use, threading, and so forth), of using Shared methods? These Shared classes raise...
3
by: Ford Prefect alias Armin | last post by:
Hello I use SHARED Sub's and Functions to access Data from all running Sessions. I use the KeyWord Shared in the Functions of the Class. This is working fine.. an I can share Data between...
15
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
8
by: gemel | last post by:
I have been reading sime material in .NET that throws some doubt on my understanding of shared procedures. With regard to object programming I assumed that variables declared within a class were...
2
by: MPF | last post by:
When designing a n-tier architecture, what is the preferred method/function accessibility? <Specifically for asp.net apps> A private constructor and shared/static methods & functions? A public...
1
by: DaBrain | last post by:
Thanks for any replies in advance. I am C# Developer messing with VB.NET because I must move MANY Functions on a web site that are written in inline HTML <SCRIPT and I want to put them all in...
2
by: Random | last post by:
Here's a design question I'm curious to know if anyone here has wrestled with before... I'm writing my data access methods in classes in the App_Code directory. I know that I can easily...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
4
by: Mick Walker | last post by:
Hi All, I am just wondering, is there some sort of overhead involved in shared or static functions and subs? I think there must be, otherwise, there would never be any need to create an...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.