Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Database Best Practice (patterns)

Posted on 2004-04-16
8
Medium Priority
?
169 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 256 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 248 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 248 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 248 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

916 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