Solved

Database Best Practice (patterns)

Posted on 2004-04-16
8
161 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
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now