groovy - Using traits for horizontal domain class reuse in Grails, a good idea? -


so want create 3 plugins include domain classes , restful service, , each build on top of each other.

conceptually, "inherit" base model way:

record > person > user

however have read friendly manual inheritance may cause performance issues.

then crossed mind since groovy has horizontal reuse capabilities (i.e. traits), may define in trait , implement trait in domain class.

composing domain classes not option me because of renaming of fields, , well, loss of convenience of ide auto-completion.

my 2 questions are:

  • in part of grails project structure best place these traits.
  • can cause different problems?

the trait source code should in

  1. grails 2: src/groovy/[package][whatever.groovy]
  2. grails 3: src/main/groovy/[package][whatever.groovy]

for example: src/main/groovy/com/my/package/foo.groovy

the main issue you'll have you'll loose ability perform polymorphic queries. example, inheritance can this:

def = record.list() 

and everything contain record, person, , user instances. kind of sql union query. when using traits instead of inheritance loose ability.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -