Link to home
Start Free TrialLog in
Avatar of hazemfadl
hazemfadlFlag for Egypt

asked on

What is better in c#?

Put connection string and some common function I use it in public class
Like {GetLastID , FillGrid,&}
Or put every function in its class
Note: I used N-tier (layer) at my work.
Thanks for help
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Why on earth would you want to put the same function in every class, what if you need to change it.

DRY : http://en.wikipedia.org/wiki/Don't_repeat_yourself
Avatar of Avodah
Okay I believe in having Utility classes. An approach you can take is creating your own framework project so it can be consumed within any of your tiers. For example

Company.Framework
Company.Application.Business --> uses Company.Framework
Company.Application.Data --> uses Company.Framework
Company.Application.Presentation --> use Company.Framework

Within your framework project you can different Utility classes that assist with different things for example serialization, data access, string manipulation, etc. Now it absolutely doesn't make sense for a class to have one method, that's not to say that a class cannot have one method if that's the only one that's relevant.

Group related functions in the same class.
ASKER CERTIFIED SOLUTION
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial