Beginner Question - Application Design

?

---

I'm writing up a sample program to teach someone the basics of
database application design. I'm using the 2.0 framework and
Microsofts default "pubs" database.
What I'd like to do is create a simple app that connects to the
database and allows browsing, editing, creation and deletion of books
and authors. I'd like to show a good application architecture, with
clear seperation of data access, business logic (simple as it is), and
presentation. The student has basically been hacking his way around
application development for a while now, but has no real idea of
design.
My class design is basically as follows, but I have a few questions.

Book - Contains only book information, knows nothing about the
database. Relates 1 to 1 with the "titles" table
Author - Basically same as Book, 1 to 1 with the "author" table

Book_Record - Inherits from Book, but adds logic needed to locate,
load, and save itself to the database given a database interface
Author_Record - Basically same as Book_Record, but for authors

Books_Interface - This class has a bunch of static methods for saving,
locating, and retreiving Books from the database. It's initialized
with database interface information during the startup of the
application and passes this information to the Book_Records to allow
them to load and save themselves.
Authors_Interface - Basically same as Books_Interface, but for authors

GUI Stuff - The GUI basically calls the *_Interfaces to retreive the
objects (Books and Authors) for display and editing and passes them
back to the *_Interfaces for saving.

Now, here's the problems and questions:
All Books have Authors, and all Authors have Books, but where should
the linking be done? It would make sense fot the Books class to have
a getAuthors() methods (or Authors property), but that seems like it
would start to clutter things up (as well as start pulling alot of
things into memory). Books themselves have no knowledge of the
database, or even the Books_Interface or Authors_Interface. To me,
that seems like it's outside of their scope. How then, do we link the
two? I'd thought of adding methods to the Books_Interface such as
getBooks_For_Author(string author_id), addBook_To_Author(string
author_id, string book_id), etc. as well as similar methods to the
Authors_Interface (getAuthors_For_Book(...)...)

Anyone have any suggestions on a clean object model?
 
?

---

That example is nice, but it doesn't fully apply. In the Custom
Objects and Tier Development example, there is only 1 "top level" type
object, the Customer. It appears this is the only object I can search
for and load There doesn't appear to be a way to pull up an Order
without first having the Customer. Orders appear to be loaded fully
when the Customer is loaded, which I consider to be bad for
performance ( If I just wanted a list of customer's names, I don't
want to pull all their orders into memory ).
Any possibility of extending the example to promote Orders up to top
level objects which I can load and search for and decoupling the
Customer and Order classes?
 
S

sloan

The code is to get you started.

You can just create your down OrderDeserializer ... same principals.

And you can populate them as you need to, using an alternate stored
procedure or sql query from the datalayer (aka, getting a different
IDataReader based on a different query).
 
R

Registered User

Now, here's the problems and questions:
All Books have Authors, and all Authors have Books, but where should
the linking be done? It would make sense fot the Books class to have
a getAuthors() methods (or Authors property), but that seems like it
would start to clutter things up (as well as start pulling alot of
things into memory). Books themselves have no knowledge of the
database, or even the Books_Interface or Authors_Interface. To me,
that seems like it's outside of their scope. How then, do we link the
two? I'd thought of adding methods to the Books_Interface such as
getBooks_For_Author(string author_id), addBook_To_Author(string
author_id, string book_id), etc. as well as similar methods to the
Authors_Interface (getAuthors_For_Book(...)...)

Anyone have any suggestions on a clean object model?

You might consider the scope provided by a real world model. A library
is a wrapper for books and has a librarian to manage details such as
the relationships between books and authors. The extra indirection
provides places for encapsulating some ugly implementation, likely
your clutter. You'll still have to figure out those relationships and
code the types accordingly.

regards
A.G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top