|
-
Mar 16th, 2010, 02:17 AM
#1
Thread Starter
New Member
Proper coding methods
Hey guys,
Sorry if this is in the wrong place, I wasn't sure which area would be best suited!!(feel free to move)..
I am trying to figure out the best way to code using OOP, so-far I have only been doing simple things using one table basically so have not run into this problem before so now that I'm using multiple tables and "joining" objects etc I'm getting a bit confused...
I have been "taught" to do OOP programming in a way where I have 3 'layers', 1st layer would be the class of an object, 2nd is the Database Access Object (DAO) which controls the database logic, and the 3rd being a "controller" which basically wraps any business logic etc
So, for example - I have a student class (with methods like getStudentNumber, getName, setName .... etc), the DAO does the actuall database SELECT, UPDATE, INSERT operations and the Controller wraps these simple db instructions into something useful, like recordLogin(which would use the DAO to check a user exists and retrieve the student object before updating the database using the DAO to record a sucessful login etc)
My problem is scenarios such as "producing a class list of students involved within a module"...
So, I have a Module class and a Student class(and the stuff in-between to update them etc), but how do I programe something like this class-list?
I'm thinking of having a "StudentModule" class which contains a Module object and an arrayList of Students involved in that module - is this right? or should I be doing this completly differently etc?
Sorry for the long description and hope I haven't confused things more!..
Any help would be great,
Thanks, Chris
-
Mar 16th, 2010, 10:23 AM
#2
Re: Proper coding methods
Welcome to VBForums 
You did pick the wrong place I'm afraid - deployment is about installing etc. So that I can move it to the correct place, which programming language (and version) are you using?
Note that using DAO is almost certainly a terrible idea, because it is seriously out of date. We have been told by Microsoft since 1998 (or maybe earlier) to not use it, and for several years it has been officially obsolete (which is much worse than "unsupported"), and is virtually guaranteed in certain situations (which are gradually becoming the norm).
-
Mar 17th, 2010, 05:45 AM
#3
Thread Starter
New Member
Re: Proper coding methods
Hey thanks - I obviously didn't read the section name properly, I thought it said development!!! oops!
I'm using VB as the code-behind for ASP.NET web app, not sure exactly what version - but I think 3.5. Using VS2008 if that makes any difference also.
Just to clarify, I'm not using any built-in DAO modules but a custom class - It's basically just to seperate all my db operations away from other code/logic etc so pin-pointing issues is easier and less code duplication...
If this isn't the right way, can someone point me to a decent tutorial covering this - the only OOP tutorials I can ever find only cover what a class is and how to use it... not the more detailed/complex stuff like database connections etc...
NB, unfortunatly I'm also using MS Access for this one (uni project and they won't let us use anything else - probably to force us to code things ourselves!!)
Thanks again for your help
-
Mar 17th, 2010, 05:57 AM
#4
Re: Proper coding methods
You certainly aren't the first to make that mistake - thread moved to 'ASP.Net' forum
DAO was replaced by ADO before VB6 (aka VB 1998) was released, and VB.Net (VB 2002 and later) has a replacement for ADO too - which is ADO.net.
It isn't surprising that you can't find OOP database tutorials, as they are essentially two different and unrelated subjects - OOP is basically about how you arrange the code, rather than what the code does.
You can find a good ADO.Net Tutorial (and other things for DB related work) in our Database Development FAQs/Tutorials (at the top of the Database Development forum)
-
Mar 17th, 2010, 07:22 AM
#5
Re: Proper coding methods
Hey,
Thanks for moving the thread si!
What you are describing is definitely a "good" way to structure your code. i.e. separate layers for the appropriate actions. One of the best examples of this that I have seen is the original BeerHouse Sample kit, which you can see here:
http://thebeerhouse.codeplex.com/releases/view/127
This has subsequently been updated to use .Net 3.5, and you can find this here:
http://thebeerhouse.codeplex.com/releases/view/33900
And also, to use MVC, but that is another kettle of fish 
I have never looked at the 3.5 version, but I am sure it is of the same quality.
This project shows exactly how data can be retrieved from the database (in a database agnostic way), sent through a Business Logic Layer, and then ultimately displayed to the client.
Hope that helps!!
Gary
-
Mar 19th, 2010, 04:13 AM
#6
Thread Starter
New Member
Re: Proper coding methods
hey guys,
thanks a lot for the replies - they are all helpful, something for me to go and work with 
Thanks again.
Chris
-
Mar 19th, 2010, 04:17 AM
#7
Re: Proper coding methods
Yip, have a look, and then post back if you have any specific questions.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|