Chapter 13. A Database Example

Reggie is a system to handle course registration for a small school.

The developers are using a database to maintain information about students and classes. The first version of the database is simple (see Figure 13.1).

Figure 13.1. School Registration Database ”First Version


A Course is a class that could be offered . For now, we'll use simple names ("Econ101" for "Introduction to Economics"). Later, this will expand to include a full title, description, and other information about the course.

An Offering is a version of a class, taught on some schedule. DaysTimes is a comma-separated string of days and times ("M10,T11,F10"). Again, there will be more information added in development.

A Schedule is a particular set of offerings that a student has chosen . There are rules about how schedules can be formed :

  • At least 12 credits

  • At most 18 credits, unless an overload is authorized

  • No conflicting times

  • No duplicate courses

Rather than being enforced by the database, these rules are enforced by code that checks schedules.

Exercise 50 Data Smells.

Refactoring deals mostly with code smells. But there are data smells too; the database community has notions of what constitutes a good data design.

  1. What potential problems do you see in this database structure?

  2. What changes to the database might address them? (Don't make the changes yet.)

See Appendix A for solutions.

In the code below, there are three classes corresponding to the tables. They start out small and perhaps are a little too focused on the data, but they're much bigger with database code added. For an introduction to database programming in Java, see the JDBC Database Access trail of the Java Tutorial ( ) or the JDBC Short Course ( ). The code uses the JDBC-ODBC driver to talk to a text-file database.

Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: