NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: OO Design and Class::DBI
by perrin (Chancellor) on Apr 11, 2003 at 20:01 UTC
    Hmm, this seems very similar to questions you've asked before about coordination of constants between a database and code. I think the only complete answer to avoiding this duplication is to make one or the other the master, and update automatically. For example, your perl code could check that types table at startup and update it to match the constants defined in your class. You can't really go the other way around in this case, since your code has specific behaviors that only apply to pending POs, and thus has to be able to "know" which type means pending.

    As with the last time though, I think you're worrying about it much more than you should be. You don't have the IDs hard-coded all over the place; you have them hard-coded in one obvious place (POStatusType) that you could change quickly.

    One thing I would do differently is abstract the fact that these type IDs exist at all by hiding them behind a set of method calls like PurchasOrder->is_pending(). Then you get a little more isolation from that stuff if you ever decide to change it.