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

痴心易碎 提交于 2019-12-06 05:49:13

The Trait source code should be 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 is that you'll loose the ability to perform polymorphic queries. For example, with inheritance you can do something like this:

def everything = Record.list()

and everything would contain Record, Person, and User instances. Kind of like a SQL union query. When using Traits instead of inheritance you loose this ability.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!