views:

149

answers:

2

I'm not using hibernate and that's not a valid alternative at all. I developed a framework based on ADO.NET. This framework has default operators for each database entity.

For example, data access layers has default operators as the following:

Insert
Update
Delete
Get
GetAll

To access this methods, we work as tha sample code below:

DataAccess.Order daoOrder;

Entity.Order entityOrder;
DataAccess.Order daoOrder;

entityOrder = new Entity.Order();
entityOrder.ID = 1090;

daoOrder = new DataAccess.Order();
daoOrder.Insert(entityOrder);

I was thinking about use static methods, so the code would be simple as:

Entity.Order entityOrder;

entityOrder = new Entity.Order();
entityOrder.ID = 1090;

DataAccess.Order.Insert(entityOrder);

Suppose that the system has 30 tables and 30 entities. We need 30 DataAccess objects running as statics objects. This static structure would save us some processor cycles and save some memory as its costs less for garbage collector.

Should I use static methods for Business and DataAccess common operators in these way? Can you talk about advantages and drawbacks about this approach? (I mean, memory, performance...)

+3  A: 

The performance differential between the two options you mention above will be virtually non existent. I would go for the cleanest and most flexible design you can manage, taking into account your domain model and other business requirements, and then worry about performance tuning once you're up and running; don't try and second guess the bottlenecks before you have built your system.

See this post by Greg Beech for an analysis of static versus instance performance..

His conclusion:

in calling a method two billion times you could save yourself around 5ms by making it static, which is a saving of approximately nothing for each method call

flesh
Greg Beech did some test but I still confused because GC doesn't work vey well on .net 2.0. As you instantiate objects, sometimes GC don't dispose them very well. That's why w3wp.exe process increase it's workset as fire in hell!
Eduardo Xavier
Well the performance hit is negligible either way, so as long as your design is sound, using static methods should be fine - it's less lines of code as well ;)
flesh
A: 

If you use static methods in this class, every object which will interact with it will be highly coupled with it. As the matter of fact your code isn't well-testable. If I were you I'd avoid using static methods/classes as well as Singletons. Unless you don't want to test-drive your app.

rafek
Sorry, that's isn't true!
Eduardo Xavier
Oh, could you please provide some explanation? Which part of my sequence isn't true? You've asked about pros and cons, and that is my point of view. Please correct me if I'm wrong.
rafek