Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > BOOK: Beginning Database Design Solutions ISBN: 978-0-470-38549-4
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Database Design Solutions ISBN: 978-0-470-38549-4
This is the forum to discuss the Wrox book Beginning Database Design Solutions by Rod Stephens; ISBN: 9780470385494
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Database Design Solutions ISBN: 978-0-470-38549-4 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 20th, 2011, 03:41 AM
Authorized User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Object Oriented Programming and Database Design

Hey.. i have been working on this project on building school applications with vb 2008 and Sql server 2005. Well i was able to design the database including the ER-model but when i enter into coding, i faced a lot of problems. I practised inheritance,interfaces and all the object oriented principles but i still cant get it. One of the major problem was i thought of making objects and using them as an interface to link the database. But i couldnt diffrentiate between tables and classes. On second thought of just dragging the forms and making modules and coding down the events but i realised it was unethical and a bad programming(though people usually do that). The next thing was i couldnt understand relations(esp. has a and is a). For example. if i make a class named Class( u know standards of students.Five,..V) and then i make a class named Student so i got confused whether i declare Class objects as member of students(has- a relationship) or just inhert Students from Class..

If you guys get my point then please reply me out.. I know there are lot of vb professionals out there who deal with these things daily. If you dont get it then post "I dont Get it!" and i will post a new one.
  #2 (permalink)  
Old March 20th, 2011, 03:41 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Implementing a database design in code can be quite tricky.

Usually a table in the database corresponds to a class in the program and records in the table correspond to instances of the class. There are also usually database objects sitting around. Possibly a top-level object that represents the database as a whole and that lets you "get" tables, and table objects that let you query for records.

You can model inheritance in parallel between the database and code. For example, an Employee class/table can inherit from a Person class/table. Handling that is easier in code than in most databases.

For the class/student example: First I try to avoid the word "class" because that's a reserved word in some programming languages so you can't use it as a class name. I use Course or Offering or something.

Next, a Student isn't a type of Course and a Course isn't a type of student so there's no is-a relationship there. A Student takes Cources and a Course has Students so they have a relationship there. You could model it as a has-a relationship: a Course has Students who are enrolled in it. I would probably make a CourseStudents table to hold the Students taking a Course. It would have a CourseId field and a StudentId field. The two fields together would make up the primary key.

(In a more elaborate and realistic model, you would probably also need multiple Sections for the Courses so the same course can be taught at different times. And that doesn't consider multiple semesters.)

So in the code, I would use separate Student and Course classes. The Course class would have a collection (or list or something) or Students taking it. Depending on what you need to do with the object, you could also give the Students class a collection of Course objects representing the courses that a student is taking.

Moving data between the database and the objects is very programming language-specific. Some make it fairly easy and others make it harder. In .NET, the latest database tool is Entity Framework, which generates classes for you based on your database. It also provides code to help populate objects and save their changes back to the database.

If you don't have good tools for that, you can write your own routines to load objects. For example, a GetStudent function might take as a parameter the student's ID or name, look up the corresponding Students record, and return a Student object. You would need to decide whether it should also populate the Student's Courses collection.

I hope that helps a bit. If I missed your question or you're still stuck, let me know.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old March 21st, 2011, 06:30 AM
Authorized User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Post

Firstly thank you for your reply.. I totally appreciate that because most of the people don't get me but you did. I saw exactly the tables as classes and rows as the objects as you say..But it becomes quite complicated when we talk about relationships in Database..For example: there are primary keys and foreign keys in database but is-a and has-a relationships in programming. Anyways i can figure it out.
Database architecture is quite satisfying to me but its the programming part as i told you earlier. So what i did is i visualized students and courses(as you referred) as a has-a relationship so i made Course object a field(member) of class Students. Then, in the interface part i made a property that only sets or gets the Course name(since course is only required) . But within the property i implicitly called the Course class property to set the course code field. How is that??
Another query i would like to know is that some people implement layers to their programming. Its part of their own logic,but they found a type of messy to put the ADO.NET codes and the programming codes together. What i mean is they separated them between layers like Database layer and Logical layer where Database Layer consist of many procedures related to data access whereas Logical Layer consist of only programming codes. It looked quite clear and easy to access. It was kind of interface between programming and database. So i thought of the same when i have to create connection time to time in different forms and event. What i did is i created a set of modules named after the Classes like DataStudents. And the module consist of set of procedures that connects the data and returns the desired value. i simply call these form the class which is easy to use. So how do like this kind of approach??
  #4 (permalink)  
Old March 21st, 2011, 06:31 AM
Authorized User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Post Layers as an interface to programming and Database access

Firstly thank you for your reply.. I totally appreciate that because most of the people don't get me but you did. I saw exactly the tables as classes and rows as the objects as you say..But it becomes quite complicated when we talk about relationships in Database..For example: there are primary keys and foreign keys in database but is-a and has-a relationships in programming. Anyways i can figure it out.
Database architecture is quite satisfying to me but its the programming part as i told you earlier. So what i did is i visualized students and courses(as you referred) as a has-a relationship so i made Course object a field(member) of class Students. Then, in the interface part i made a property that only sets or gets the Course name(since course is only required) . But within the property i implicitly called the Course class property to set the course code field. How is that??
Another query i would like to know is that some people implement layers to their programming. Its part of their own logic,but they found a type of messy to put the ADO.NET codes and the programming codes together. What i mean is they separated them between layers like Database layer and Logical layer where Database Layer consist of many procedures related to data access whereas Logical Layer consist of only programming codes. It looked quite clear and easy to access. It was kind of interface between programming and database. So i thought of the same when i have to create connection time to time in different forms and event. What i did is i created a set of modules named after the Classes like DataStudents. And the module consist of set of procedures that connects the data and returns the desired value. i simply call these form the class which is easy to use. So how do like this kind of approach??
  #5 (permalink)  
Old March 21st, 2011, 10:16 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Yes, multi-tier architectures are popular. Probably the most popular is the 3-tier architecture where there's a user interface tier on one end, a database tier on the other, and a middle tier that translates between the two. The idea is that you can change the user interface without affecting the database and vice versa.

For your program, you might write a middle tier to load data from the database and create objects with it. (And conversely save changes back into the database from the objects later.) The database "tier" is actually the database so you don't need to build that, you just need the middle tier to use it.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Oriented Programming and Database Design Pronoy Pradhananga Visual Basic 2008 Professionals 0 March 20th, 2011 03:40 AM
Object Oriented Programming jgrant C# 2005 0 March 16th, 2007 03:04 AM
Object oriented programming with VB6 james gold Pro VB 6 3 September 27th, 2003 02:31 PM
Object oriented programming with VB6 james gold VB How-To 2 September 23rd, 2003 09:29 AM
Object oriented programming with VB6 james gold Beginning VB 6 3 September 18th, 2003 02:56 PM



All times are GMT -4. The time now is 11:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.