Friday, October 17, 2014

Adding common methods to Grails domain objects

If you don't want to change your domain hierarchy, but need to add common function to multiple domains without copy/paste, one simple option is to create and implement trait. For example:
class Test implements LogTrait {
  String name
}

trait LogTrait {
  def springSecurityService

  def afterInsert() {
    log.info(this as JSON)
  }
}
Nice bonus is that events and injected services work just fine as it would be in original class.


1 comment:

  1. Along with roulette, have the ability to|you possibly can} play 1,200-plus other on line casino video games, and the celebration begins with a one hundred pc up to as} one bitcoin welcome bonus. Once you are in entrance of the roulette wheel, you would possibly ponder whether you have chosen the most effective roulette recreation. However, once you play online roulette at 카지노사이트 the most effective roulette recreation websites, you'll see that your life will be made easier by way of numerous info on the totally different versions of the sport. In a conclusion, we will to} truthfully say that enjoying in} roulette online is method higher than enjoying in} at a land-based on line casino. First of all, on the Internet, might have} far more roulette variations select from|to select from}. This helps all players determine on} the easiest version which fits their preferences the most.

    ReplyDelete