Re: Subclassing a DataObject

From: Mike Kienenberger (mkienen..laska.net)
Date: Fri Jul 01 2005 - 11:01:38 EDT

  • Next message: Mike Kienenberger: "Re: Expression: NOT EXISTS... JOIN..."

    "Michael Gentry (Yes, I'm a Contractor)" <michael_gentr..anniemae.com>
    wrote:
    > You know, I've been thinking it would be nice to have a tri-class
    generation
    > option in CM, too, but my interest would be to support validations (as the
    > Cayenne validations, while cool, are too early for my interests --
    validate
    > on state transitions, not saves/etc). You'd have something like:
    >
    > com.foo.generated._Bar (Cayenne auto-generated)
    > com.foo.logic.Bar (Generated once, add your business logic/etc)
    > com.foo.validation.Bar (Generated once, add your validations)
    >
    >
    > And then everything you instantiate would be the validation layer. Of
    > course, if Java had Objective-C categories, this wouldn't be needed.
    >
    > The benefits of this are you can isolate all of your validation methods in
    a
    > separate class from the getters/setters and the business logic. In a
    > complex application, the validation layer can be much larger than the
    other
    > two layers (the application I'm maintaining is proof of this -- our most
    > complicated validation class is over 200KB). You put the validation layer
    > at the bottom of the chain, too, because it might need access to the other
    > two layers.
    >
    > Of course, I could just be a loon, too. :-)

    You can do it -- it just takes a little effort.

    To support vertical inheritance, I'm generating tri-levels.

    com.foo.generated._Bar (standard cayenne)
      com.foo.generated.__Bar (adds in the attributes and relationships of
    ancestors)
        com.foo.logic.Bar (my business logic)

    You just switch away from makepairs and generate each level by itself.
    You have to do it via ant tasks rather than via the modeler, but eventually
    that'll change.

    [Actually, because there's some bugs in the latest cgen v1.2 that I haven't
    fixed yet, I cheat and generate the top and bottom layer with cgen, then
    manually edit the superclass of the bottom layer -- it never gets generated
    again anyway].

    -Mike



    This archive was generated by hypermail 2.0.0 : Fri Jul 01 2005 - 10:58:48 EDT