Building a Utility Library Without Going Overboard

I realized a while ago that I was breaking the "DRY" (Don't repeat yourself) rule pretty severely when looking at my various projects as a whole. I generally focus on not repeating code within an application but I have not been careful enough with this rule when starting new projects. Many times when I need a particular function that I have written before I will just go hunt it down and copy the code into my new project. It has recently become a problem because I now have the same function littered throughout my different programs with various modifications made to each!

It's time for me to build a utility library that will become the main source for commonly used functions in my applications. The main need that I saw for this library was the simple but tedious task of creating an email message and sending it along via a web contact form. Just about every .NET web site I've ever built has needed this functionality and each time I created a new MailMessage and Email class to handle the job. This was the first thing I added to my new Utility Library.

The purpose of this post is to try and get some feedback on which functions you would include in such a library and which you would leave out. The last thing I want to do is create some bloated set of code filled with methods that are rarely used. If anyone is interested in seeing how I am going about creating this library (or would like the actual library) just let me know in the comments and I'll do my best to help out.

Here is the initial structure and the classes I'm starting with:

Utility Library Structure

Each class contains a few functions that I find myself using frequently. Here is the class diagram for the few classes I have so far:

Utility Class Diagram

Again, if anyone wants the actual code or libraries let me know.

Help!

If you were building a utility library, what would you include or exclude? Anyone? Bueller...?

EDIT

I've added the source code for the project to the post for anyone interested. Since the post I've added a couple more functions to the library.

SevenLabs.Utilities.zip (35.55 kb)

kick it on DotNetKicks.com


Related posts

Comments

May 16. 2008 03:14 PM

alewis

Looks good...Would love to see the code behind the idea....

alewis

May 16. 2008 03:39 PM

Matt

No problem, i've added the source code to the post.

Matt

May 21. 2008 07:43 PM

Bill

I think a good edition would adding a download helper to transmit files in chunks etc. Smile

Here is a good example: www.gridviewguy.com/ArticleDetails.aspx

Bill

May 22. 2008 09:35 AM

Zack Jones

How about functions such as creating and returning a connection to the database and Command Objects. I use those all the time and usually copy the "util" class from project to project.

Zack Jones

May 22. 2008 11:16 AM

Matt

@Bill,
You're right, that would be a good and useful addition.

@Zack,
I thought about that as well and you're probably right. I was concerned with adding that type of functionality because I though I would have to be database engine specific, but maybe that isn't such a bad thing. It couldn't hurt to have a SQLServer helper and a SQLite Heleper etc.

Thanks for the input guys!

Matt

May 26. 2008 02:53 PM

Software vulnerabilities

It's always hard to know how to split things up in assemblies etc. Since I regularly do not only asp.net apps, but also winforms and also command line apps I aim not to get a lot of extra unwanted dependencies. So at least I have a separate DB helper dll, a separate string/utilities dll. And trying to do a web helper dll, a winforms helper etc...But it's hard to take the time to structure it and actually DO it, although I know in the end I would gain from it. Too easy resuing code with copy and paste I guess Smile

Software vulnerabilities

May 26. 2008 06:16 PM

Matt

That's a really good tip, I think that makes a lot more sense than trying to build a single giant helper dll. I will go back and restructure the project that way which should help the goal of keeping the bloat out and the libraries concise! Thanks!

Matt

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 23. 2008 09:30 PM

Search

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008