Solved

Database Best Practice (patterns)

Posted on 2004-04-16
8
164 Views
Last Modified: 2010-04-24
Well, this is more of a best practice question then actually how to do something.

I am developing an app (practice) where it is talking to a database.  Everything is working fine.  

The database consist of 3 tables, personnel, course_xref, and course.  As you can guess, the course_xref table consists of personnel with many courses.

I am creating a class within VB that would concidered a personnel record, with many of the same fields within the personnel table.  Now....

Should I create a course class and have an array of courses within my Employee class OR should I dynamically create the list of classes when it is needed.  (If I am displaying information regarding an Employee and I want to see all courses this person has taken, do I want to display it as text or store each one into an array of objects and display each one that way. )

Thanks for your help.
0
Comment
Question by:lfabbric
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 64 total points
ID: 10849016
a courses class (the collection of class objects that represent the classes taken by a given person is the best appraoch).  The courses class would then have a FACTORY method, to add a new class to the person - so that classes could NOT be created as a stand-alone entity, but by being associated with a specific person.  So the Course class would NOT have a PUBLIC constructor, and thus could not be independently created as a New Course

Dim course as New course

would fail to compile,

where

Dim course as Course = course.Add(PersonID)  

would create a new course object, and assign it to the person whose Id you pass in the Add mthod call.

AW
0
 
LVL 2

Assisted Solution

by:navneet77
navneet77 earned 62 total points
ID: 10875958
What if he needs to get the list of available courses. Then it wont be associated with any person. I think lfabbric needs to analyse what he wants to achieve and what are his requirements before making the right decision.
0
 
LVL 27

Expert Comment

by:planocz
ID: 10877552
Hi lfabbric,

Here is where I found a good example for Databases in VB.Net

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:lfabbric
ID: 10878561
I have to browse courses by both employee's and courses.  (I am just playing around with a production application and converting it into ASP.NET/VB.NEt)

The application allows people to browse courses by course or by person.  Or make reports based on courses and show all people who have taken courses.  I think ... I need to be looking into the Factory Pattern.  It has a few examples as to how to handle this kind of things.

Does anyone have any comments on this.
0
 
LVL 27

Assisted Solution

by:planocz
planocz earned 62 total points
ID: 10878641
Hi lfabbric,

Here is another link for ASP.net examples....

http://www.asp.net/Default.aspx?tabindex=9&tabid=47
0
 
LVL 1

Assisted Solution

by:M_o_n_t_y
M_o_n_t_y earned 62 total points
ID: 10882257
I would create a collection class of courses that has all the regular collection methods you need plus a method like LoadForEmployee() that takes an employee ID as an argument. This way you can use the collection in a 'stand-alone' way when you only care about the courses and not employees, and the employee class can also expose the collection as a read-only property.

In regards to whether or not to load up all the course objects in the employee object or to wait until they are actually needed, ask yourself these two questions:
1) Do I often have many employee objects loaded up at concurrently?
2) When I load up an employee object, am I usually going to access it's collection of Course objects?

If number one is yes and/or number two is no, you'll probably want to employ a JIT technique where when the course collection is requested from the employee object, it first checks to see if it exists, and if it doesn't it creates it and then returns it.

Hope that helps...
             
                                 -Monty
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question