Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form & Connection Class Design

Status
Not open for further replies.

jayplus707

Programmer
Jul 29, 2002
17
0
0
US
This is a general object-oriented design question: How would you design your application where each form was an object and needed a connection to the database? Does it make sense to make the connection and other data part of a connection class that is external to each form class? Or would you somehow incorporate the connection as part of each form class?

I was going to design it this way: have 1 to n form objects, but have a single connection object that all the form objects have access to. Is this the better way to design it?

If you know .NET, how would you do this in C#? Each form in C# is itself a class. Where would you create the connection object? Because if you create the connection object in a form class, the connection object is no longer "global" to the other form objects. Have I confused you? Because I am confused now......Thanks.
 

Yes, creating a seperate class for your connection (in .net use a module as you would in 6.0) and then each of your forms could use it.

Good Luck


 
Since you're asking your question in OO terms, I'd repsond by asking if you've considered why your form needs to know anything about the database? Part of the principal of encapsulation is ensuring that responsibilities are divided among classes such that each does one job well. I'd say you were looking at perhaps three (maybe four, maybe more) classes here: (1) the form (2) the business object that's displayed there (3) the database representation of the business object (4) the connection to the database where it's stored (OK, four then!).

Mike
 
Thanks so much for your help so far....What I've done is created 3 different forms and pass the dataset and connection to each of the forms when creating the object....ie.

frmTitle newForm = new frmTitle (myConn, myDataset);

Is this how you could do it? I guess it boils down to trying to "share" the same connection and same dataset between each of my forms.
 
Hi,
Well i have taken it from MS site...but might be useful for somebody....

I guess u can go for Microsoft Data Access Application Block for .NET; which is basically consists of a single .NET-based assembly, which allows all of the functionality necessary to perform the most common data access tasks against a Microsoft SQL Server 2000 database.

Specifically, the Data Access Application Block helps you:
1) Call stored procedures or SQL text commands.
2) Specify parameter details.
3) Return SqlDataReader, DataSet, XmlReader objects, or single values.

The Data Access Application Block has been designed to encapsulate Microsoft's recommended best practices for data access in .NET applications, as described in the Microsoft Data Access Architecture Guide.

By using the Data Access Application Block in your applications, you can:

1) Minimize the data access code you need to write, often to a single line.
2) Ensure that your data access logic is implemented in an efficient and effective manner.

- Kashyap
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top