Shared/Static methods & functions

  • Thread starter Thread starter MPF
  • Start date Start date
M

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
 
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/issues/05/01/StaticsinNET/default.aspx
http://odetocode.com/Articles/313.aspx
http://odetocode.com/Articles/314.aspx

I hope this helps out,
 
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.
 
Thanks for the clarification.

Dmitriy Lapshin said:
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 said:
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
 
Back
Top