By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,890 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,890 IT Pros & Developers. It's quick & easy.

Shared/Static methods & functions

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.