1

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...)

4

2 回答 2

3

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

于 2009-07-13T19:49:48.873 回答
1

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.

于 2009-07-13T19:57:33.087 回答