Data and Object Modeling: The Schema and the Package

When generating object models, I prefer to package related classes together. For instance, a Calendar would have the following classes:

calendar.Calendar
calendar.CalendarDAO
calendar.CalendarService
calendar.CalendarGateway

Since my controller or view will never invoke methods on my CalenderDAO or CalendarGateway directly, I can secure the methods in those classes by setting access="package". Another subtle benefit is that the component files are organized in a single folder...

Now, in my data model I would obviously have a Calendar table, but I might also have related tables like CalendarType and CalendarStatus.

At the risk of labeled a flake, I think it would be interesting to group related tables by schema in my data model like so:

calendar.Calendar
calendar.CalendarStatus
calendar.CalendarType

The downside to using a schema to group related tables is that you are thereafter forced to prefix you table names with the schema (SELECT * FROM calendar.Calendar). With all database access managed by a DAO, this isn't a show stopper for me, but if I were to pepper my site with query calls in multiple cfm templates, I would probably curse every extra keystroke. To mitigate this, I could also shorten the package and schema namespace to "cal.", since "calendar." is rather verbose.

Another (small) downside is that MySQL does not support schemas, so I would have to use MSSQL, Postgresql or any other RDBMS that supports schemas.

The question for me is, "if a schema is to a data model what a package is to an object model, does it make sense to use schemas?". Does anyone out there ever use schemas? If so, to what effect?

Comments
Peter Bell's Gravatar I used them for a while. Actually, I just used table prefixes based on functionality so I had cms_User (users were part of core CMS), cat_Product and cat_Category (products and categories were part of a catalog), com_Order and com_OrderItem (as they were part of a commerce package) and so forth.

At first I liked it as I felt I'd have related tables next to each other. Eventually I found it was more trouble and I preferred just being able to find all tables alphabetically so I stopped the practice recently.

I don't see a big win either way. I'd play with both and see what works for you . . .
# Posted By Peter Bell | 5/14/07 3:58 PM
Rob Wilkerson's Gravatar I just use a basic naming convention. I like to see related tables nicely grouped in my table list so, using your example (but my naming convention :-), I'd just have calendar, calendar_status, calendar_type. For my purposes, that does exactly what I need.
# Posted By Rob Wilkerson | 5/15/07 6:18 AM
Aaron Roberson's Gravatar I have been doing the exact same thing for a while now. I started to do the following:

com.product.product
com.product.productService
com.product.productDAO
com.product.productitem.item
com.product.productitem.itemService
com.producut.productitem.itemDAO

Then I had to create aliases for all of my object names in LW and it became a mess. I'm reverting back.
# Posted By Aaron Roberson | 5/18/07 12:57 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner