Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call groovy parent class method - Grails

Tags:

grails

groovy

I have a Grails service,

Parent Class:

class BarService{

  def fetchData(params) {

    return fooData.toString()

  }

}

Child Class:

class FooService extends BarService{

  def fetchData(params) {

    def fooData =  super.fetchData(params) //this will call the BarService method

    return fooData 
  }

}

Is this the right groovy way of doing it? Because to me this looks like Java

Thanks

like image 577
Trt Trt Avatar asked Oct 16 '14 09:10

Trt Trt


1 Answers

As per your example, there is not much that can be done, except maybe removing the optional return keyword:

// Parent Class:

class BarService{
  def fetchData(params) {
    params.fooData.toString()
  }
}

// Child Class:

class FooService extends BarService{
  def fetchData(params) {
    super.fetchData params
  }
}


assert new FooService().fetchData([fooData: 900]) == "900"
like image 171
Will Avatar answered Nov 12 '22 22:11

Will