Code Reusability

Posted by Sudhak under ASP.NET on 1/7/2009 | Views : 2320 | Status : [Member] | Replies : 1
1. Lets say I have this hypothetical database (the one I am dealing with is much bigger as you probably can imagine or guess):





I have many applications which need customer's ID, Name, and Address, Items' ID, Description. Is it better to create a library which can load the customer ID, Name, and Address and same for the Items by invoking a stored procedure or is it a better design to have a stored procedure which will get whatever I need for the specific application. For example, one application might need customer's id, name, and the number of orders and it might need what items we carry. However, another application might need all the columns of customer and Items. Because too many applications need customers' ID, Name and Adddress, should I create a static class class with static method which invokes a stored procedure and gets the information and if I need more information in other application I simply get those as per need basis, or should I just skip creating a static class library and get everything when I need them by invoking some stored procedure which returns all I need.

If I create a library, the advantage is I can use it in many applications and get the extra columns if I need to (but at least a few apps will not need the extra columns so simply calling the static methods will do the job). However, if I need other columns then I have to get those separately. If I do not create a library, I do not have the advantage of code reuse but I can get whatever fields I need and load them as need for the application all in one shot. I am wondering which solution is more advantageous over the other? Or, is there a better way?


Posted by: Raja on: 1/8/2009 [Member] Starter

My experience says, the first approach is good. Create a library and use it everywhere instead of writing code everywhere.

In the first approach you will not only achieve code reusability but also less maintenance time as if you need to change certain functionality or field tyes/names you need to do it once and it will effect everywhere while in the other case you will have to do it everywhere separately.

So creating first approach is good. Its like doing SOA (Service Oriented Architecture).


Raja, USA

Sudhak, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response