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. :-)
/dev/mrg
> From: Mike Kienenberger <mkienen..laska.net>
> Reply-To: <cayenne-use..bjectstyle.org>
> Date: Thu, 30 Jun 2005 18:36:58 -0400
> To: <cayenne-use..bjectstyle.org>
> Cc: <cayenne-use..bjectstyle.org>
> Subject: Re: Subclassing a DataObject
>
> Kevin Menard <kmenar..ervprise.com> wrote:
>> Mike Kienenberger wrote:
>>
>>> There's probably a better way to solve your testing problem, but I don't
>
>>> have enough info (either that, or enough brain cells) to provide any
> ideas.
>>
>> Hmm . . . there are certainly other ways, and they are better than
>> adding another DataMap. The goal here is transparency. In the general
>> case, the rest of the system uses interfaces, so it's not particularly
>> bound to the DataObject. But it'd be nice if the client didn't really
>> need to know about Cayenne rules when looking to subclass.
>
> I think I understand the issue better now after having given what I sent you
> earlier some thought.
>
> Cayenne cannot instantiate your subclass because all DataObjects are
> instantiated by class name.
>
> Perhaps you can just programmically update your data map with the new class
> name for the test subclass.
>
>
>> Perhaps the velocity templates should be updated to make these generated
>> classes final then?
>
> Maybe. I'll let Andrus chime in on that one. It does seem like it might
> be a good idea. On the other hand, since you can modify the DataMap to
> provide a different name, then it's possible that what might be a "final"
> class for one DataMap may not be the final class in another DataMap.
>
> This would especially be true once you start dealing with supporting
> inheritance, although the template could certainly detect those cases.
This archive was generated by hypermail 2.0.0 : Fri Jul 01 2005 - 10:32:09 EDT