What's the proper way to invoke super.beforeInsert() for a Domain class?

View: New views
3 Messages — Rating Filter:   Alert me  

What's the proper way to invoke super.beforeInsert() for a Domain class?

by Matthew.Lachman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have domain classes similar to the following:

class A {
        //Some properties

        def beforeInsert = {
                //Do something interesting
        }
}

class B extends A {
        //Some added properties

        def beforeInsert = {
                super.beforeInsert() //doesn't actually call
A.beforeInsert()
                //Do additional interesting things
        }
}

What's the proper way to achieve the effect I'm looking for?

Thanks,
Matt

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: What's the proper way to invoke super.beforeInsert() for a Domain class?

by Burt Beckwith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have beforeInsert delegate to a real method:

class A {
   //Some properties

   protected void onBeforeInsert() {
      //Do something interesting
   }

   def beforeInsert = {
      onBeforeInsert()
   }
}

class B extends A {
   //Some added properties

   @Override
   protected void onBeforeInsert() {
      super.onBeforeInsert()
      //Do additional interesting things
   }
}

Burt

> I have domain classes similar to the following:
>
> class A {
> //Some properties
>
> def beforeInsert = {
> //Do something interesting
> }
> }
>
> class B extends A {
> //Some added properties
>
> def beforeInsert = {
> super.beforeInsert() //doesn't actually call
> A.beforeInsert()
> //Do additional interesting things
> }
> }
>
> What's the proper way to achieve the effect I'm looking for?
>
> Thanks,
> Matt
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>


signature.asc (204 bytes) Download Attachment

RE: What's the proper way to invoke super.beforeInsert() for a Domain class?

by Matthew.Lachman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Burt - seems obvious now that I see it.  Another approach that
was suggested on the Groovy list by Roshan Dawrani was:

=================================
class A {
    def beforeInsert = {
        println "A->beforeInsert()"
    }
}

class B extends A {
    def getSuperClosure() {
        super.getBeforeInsert()
    }
    def beforeInsert = {
        getSuperClosure()()
        println "B->beforeInsert()"
    }
}

new B().beforeInsert()
=================================

I'll give both a shot.  :)

Matt

-----Original Message-----
From: Burt Beckwith [mailto:burt@...]
Sent: Sunday, November 08, 2009 9:19 PM
To: user@...
Subject: Re: [grails-user] What's the proper way to invoke
super.beforeInsert() for a Domain class?

Have beforeInsert delegate to a real method:

class A {
   //Some properties

   protected void onBeforeInsert() {
      //Do something interesting
   }

   def beforeInsert = {
      onBeforeInsert()
   }
}

class B extends A {
   //Some added properties

   @Override
   protected void onBeforeInsert() {
      super.onBeforeInsert()
      //Do additional interesting things
   }
}

Burt

> I have domain classes similar to the following:
>
> class A {
> //Some properties
>
> def beforeInsert = {
> //Do something interesting
> }
> }
>
> class B extends A {
> //Some added properties
>
> def beforeInsert = {
> super.beforeInsert() //doesn't actually call
> A.beforeInsert()
> //Do additional interesting things
> }
> }
>
> What's the proper way to achieve the effect I'm looking for?
>
> Thanks,
> Matt
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email