[Feature] Add generator option for human and machine classes

10 views
Skip to first unread message

Martin Devillers

unread,
Jul 24, 2015, 5:41:29 PM7/24/15
to greenDAO
Hello,

First, thanks a lot for the great work creating this library! I noticed that it has started seeing some activity again lately, so I thought I'd share this idea that I've had for a while. 

I think it would be nice to have an option on the generator in order to create two sets of classes for the model: human and machine classes.

If you're not familiar with the concept, check out the mogenerator project, which is an iOS command-line tool for generating model classes (and it's very popular). What it does is that is creates two set of model classes: the machine classes, which declare the database columns as class properties with their getters and setters, and the human classes which are by default empty and just inherit their respective machine classes. The DAO creates human class instances when loading entities from the database. When the model is re-generated, the machine classes are completely overwritten, but the human classes are left untouched if they already exist. 

This is an awesome pattern. It's cleaner than using keep sections (although the two aren't actually incompatible), and it provides better code readability. Looking through the activity around the project, the only similar idea that I've found is request #168, although it's not exactly the same thing. 

From what I've seen looking at the GreenDAO source code, this shouldn't be too hard to implement, and it can be added as an option on the schema in order to maintain the previous behavior by default. I'll gladly do it myself.

Thoughts?
Reply all
Reply to author
Forward
0 new messages