?
---
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?
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?