Last post Sep 28, 2011 11:45 AM by nitin.virgo
Sep 20, 2011 08:55 AM|DaveFromNH|LINK
I'm building a library project to contain routines common to my asp.net and batch environments.
I can design it one of two ways;
1) I can pass simple objects (byref intA as integer, byref strB as string, byref dteC as date) and include all of the code necessary to open the database, select rows from views, build and launch e-mail, etc... or;
2) I can pass more complex objects (byref sqlA as SqlConnection, byref smtpB as SMTPClient)
Option #2 would be easier to code, but is there a "rule of thumb" for deciding what to pass?
Sep 20, 2011 09:10 AM|toas1|LINK
I dont think there is a best practice for it
If #2 is what you prefer then go for it. In my opinion, unless you have performance issues (like calling your method many thousands of times a second) you should choose what makes your code most readable.
Sep 20, 2011 12:58 PM|LudovicoVan|LINK
I might be missing the point, but I'd prefer option 1, so that the relevant logic is coded just once in the library rather than n times for the n possible clients.
Sep 21, 2011 02:17 AM|toas1|LINK
just one thing. If you go for #1 remember not to send value types by reference (like you do with "intA" in your example) if you dont have a very good reason for it. it will only cause the value to be boxed and you should avoid if it if you can.
Sep 28, 2011 11:45 AM|nitin.virgo|LINK
I will prefer option2 because of following reasons:
1. we should inject dependencies and function itself should no longer responsible to create object.
2. We can do TDD easily on this function.