OOP Newbie Question... DB read/write, from where?

todonnell69

Member
Joined
Jun 8, 2005
Messages
15
Programming Experience
5-10
Hey all,
If I am instantiating an object from code, and that object will be populated by(or saved to) a database, where should the code reside that actually makes the connection to and reads from the DB? Do best practices dictate the connection is made in the code that calls the object or in the class itself? If it goes in the class itself, I guess I would need to pass in the connection info which would not be a problem, but is this how it's commonly done?
Thanks in advance...
Tom
 
It can speed up development overall if you create a reuseable data access framework. You could create your own or I have seen other developers post their's on various web sites. If you aren't going to do that, I'd say that most people, including myself, add the required data access components to a form in the designer. If you want to create separate classes then you have to write all the code yourself, whereas the Windows Forms designer can generate the vast majority of the code you need for you.
 
Back
Top