I read Sloans post in my last thread but I did not quite understand it.
I have written my own custom object BASED around sloans object that he
posted.
Can anyone answer the questions at
http://thedogsatonthemat.com/viewtopic.php?t=21 ?
(I put it in my forum so the code is cleaner. You can reply here
instead of on the forum).
I also have a question regarding static vs intiated DALS.
Couple of questions about this OOP design:
1) Is it really neccessary to have UserManager? Could I not integrate
UserManager methods/properties in the User >class or UserCollection class
(UsersForCar would probably go in class Car right?)? Would doing that ruin
proper OOP >design? Performance?
Yes. Seperation of concerns militates for seperating them. UserManager
contains all your grungy database code, and squarely in the "back end" of
your application. User and UserCollection are used across all tiers of your
application.
2) How about performance? When you get a Car's users, you hit the DB twice.
Once to get the User IDs for a car, >then the second to load each user. How
ever....I could instead load the user object and its properties directly
thing is....if I wanted to load One User >object only..then I would have to
write LoadData logic for the User object.
Managing performance is a challenge in this design, and it's another point
in favor of a consolidated data access layer (UserManager). In UserManager
you have the option of retrieving and updating related tables in optimized
ways, instead of always sending a single database query for each entity on
load an update.
3) Is this design good? It implements lazy load design for the Cars Users
property because it only loads if needed. >Would this be bad performance
wise vs SQL returning multiple result sets for multiple collection loading
(etc >UserCollection for cars)
You have to manage these tradeoffs based on the use cases for your different
objects.
4) When does these methods go?? Like should GetUsersForCar be in the
UserManager object or Car object???
Implemented in UserManager, invoked from Car perhaps.
5) Is there some parts I could centralize??
I don't understand what you mean.
6) Should ID (like User ID) be Id or ID? I know silly question and I know
the answer is Id...but I feel like using >ID. Bad Naming convention?
Personal preference.
I really like this idea of True OOP binding instead of DataTables/DataSets
but I'm really worried about performance >overall. The SQL Server will
prolly get hit bad if say 25 users were to load the car object and query
the Users >property (thats 25 x 2 = 50 hits compared to 25 hits with
DataTable) but I hate binding with the DataTable.
First, the typed DataSet avoids late binding, and has the integrated
TableAdapter framework, so it's quite attractive. But there's no reason why
your approach should suffer poor performance. The DataSet will have to
issue multiple SELECT's for multiple DataTables too.
IMO one of the most attractive features of your approach is that you can use
nullable types in your entities, and have excelent type-fidelity between
your entities and database tables.
David