Hi,
I'm trying to learn the whole DAL architecture and make sure I really understand and the relationship between objects and relations, and I have a few questions. I've been reading MArtin Fowler's enterprise arch book and am trying to work out what patterns are being used.
I /think/ TBH uses Table Gateways but if so, I don't get why in ArticleDetails.cs it represents data from more than one table e.g. it contains Category Title from the Categories table, yet the Articles class lazy loads Category Title anyway, so why is it needed in ArticleDetails? The stored proc is doing an inner join on articles and categories.
Also regarding the Providers, does TBH have just one ArticlesProvider covering all 3 entities for simplicity or is this achieving some deliberate purpose? I figure this has all been done for a very good reason, but I'm a bit in the dark as to why. I was thinking about how I might implement the DAL and came up with:
DAL:
ArticleProvider, CommentProvider, CategoryProvider (the table gateways - direct mapping to DB structure - no additional fields e.g. Category Title)
SqlArticleProvider, SqlCommentProvider, SqlCategoryProvider
ArticleDetails, CommentDetails, CategoryDetails (populated by table gateways)
BLL:
Comment.cs, Category.cs, Article.cs (which has a Category object and list of Comment, which come from a lazy load)
Here I build up my domain objects so that Article objects have the Category and list of Comment objects for that Article.
The reason I would do it like this is because then I have a nice simple model which I could extend to include a photo app and blog which share tags, by using a code generator (e.g. easy for me to write a script if there was a single table adapter for each table, and corresponding ObjectProvider and SqlObjectProvider classes) and I could handle the logic to get/store related data in the BLL. The way the DAL is currently done (one provider class per entity, and stored procs getting data from multiple tables) would probably need to be done by hand because of the custom fields from >1 table in some of the table adapters.
So my questions (and there are quite a few!) are:
- What DAL pattern does TBH use (beyond the provider model)?
- Why does ArticleDetails have a Category Title property when the Article class in the BLL lazy loads this on request? Is this not redundant?
- Does my approach make sense, and if not what am I missing? Ultimately I'm trying to understand the DAL, and would really like to code-generate it as a learning exercise.
I am relatively new to all of this and hope I haven't completely missed the point! I'd appreciate your thoughts :)
Rich
p.s. jimibt if you are reading this then you will be pleased to know I am
trialling Flixon! However to help me learn the nuts and bolts I'm
ripping up the code to see what I find :)