The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

really basic OO question from n00b

So I'm a code-grinder who learnt web apps the hands-on way, and now I'm trying to be more structured, getting my head round OO, UML, data access layers. That's why this next question is, without doubt, stupid in several ways.

My hypothetical vanilla ASP.NET/SQL2K website has articles (products, vacancies, whatever). It has a page called listofarticles.aspx, which has a list of article titles, each one with href=article.aspx?articleid=n, and a page called article.aspx, which displays the details of the article. The database has a table called 'articles'. So far so good.

Now I write an Article object as a wrapper, so I can initialise myArticle and then do things like lblTitle.Text=myArticle.Title rather than having to call stored procs with parameters each time, but behind
the object are CRUD stored procs.

Now I want some sort of object as a wrapper for displaying a list of articles on listofarticles.aspx. The actual database operation here isn't the R in CRUD for the last one, it's a SELECT ID, Title FROM tblArticles ORDER BY Datecreated DESC. So there's no point in retrieving data via the stored procs I have wrapped in my Article objects. Do I have an ArticleList object with the less narrow SELECT query in it, and populate a collection of Article objects as a property of ArticleList? This seems extra hassle and I still need to change two stored procs, not one, if the table changes.

How do I reconcile this? Assuming I'm staying in the vanilla ASP.NET/SQL2K setup where I'm at home, not switching to an OO database or something?

Again, please be kindly if I've said anything particularly stupid, I'm still trying to understand OOP. Ta very much.
pottersfield Send private email
Friday, August 05, 2005
i would do it the way you have described, with the articlelist object that owns the collection of article objects.  this is sometimes called a collection class.

how you populate it can vary and depends on the # of objects, requirements, etc.  you can do it with 2 separate queries as you indicated, or with one query that returns all of the article objects and populates both the collection class and all of it's individual article instances at once. 

good luck -
Friday, August 05, 2005
If you're still watching this, buy yourself an O/R Mapper. LLBLGen Pro is the standard in the .NET world, but there are others in the works. Or, failing that, I am pretty sure there is a demo; try it, and then you'll want to buy it.

Basically, it will generate entity and collection classes by reading the database scheme right from the database; and it generates code to do a bazillion other things (filtering, sorting, calling SPs) so that you hardly ever _need_ SQL unless you have a complex query or speed issues.
Jesse Millikan
Monday, August 08, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz