Using shared (static) members

Hi!
Is anybody aware of any drawbacks when using shared (static) members inside classes. Apart from design issues and braking some of OOP rules, are there any performance issues, like bad memory usage or increased overhead when calling them?
[246 byte] By [papadi] at [2007-12-16]
# 1
Actually, the code analysis tool in Visual Studio 2005 recommends to make methods static, if they don't use any instance member variables, because under the hood the "this"/"Me" reference is always passed in to the method as a parameter, which is unnecessary overhead.

But considering the benefits of good OOP design and being able to override methods (which you can't do with static methods), I only make methods static if I need too.

DanielRieck at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Hi Daniel,

What I have in mind is using some private variables as shared for caching purposes. I'm not talking about some large amount of data, just some data to avoid database operations.

papadi at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3

In that case, you would need to store some information about how old the data in the cache is and reload it if it's too old. If you're using shared variables for this, every class who wants to read the data would have to perform this check.

A better solution would be a Singleton class that holds the data and can load it from the database if the cache has expired.

DanielRieck at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4
I consider that my data will never expire, during application life time.
So, back to the performance issue. It seems that you are not aware of any performance drawback using shared members.
papadi at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5
ps 1. I think My.Brain would be better than Me.Brain. I would make it easier to find!
ps 2. I some times think that Brain should implement the IDisposable interface. Just in case!
papadi at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified