• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling super.onDelete() of JCN in message broker

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are trying to standardize or define coding guidelines for message broker. In that effort, We decided to call super.onDelete() while overriding onDelete() in Java compute node in Message broker. While doing so, I feel like calling super.onDelete() should be the first statement before defining any cleanup work in onDelete(). But my colleague suggested to call super method at the end of overriding method. What is the good practice? Please let me know.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on the order in which you want to clean up. Does your data depend on the super class' data? Then call super.onDelete() at the end. Does it not? Then it doesn't really matter.

Whatever you do, if you call such an important call to super.xxx at the end of the method, add it in a finally block. For instance, when overriding finalize:
This will ensure that the super class' finalize (or onDelete etc) is always called. Of course this is not needed when you start with this call.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally we override a method to add some extra functionality/ functionality specific to the derived class. Now normally we would like the base functionality to be executed first and then the overriden one, in that case is it not a good practice to invoke the super method at the beginig of the method ? I can give an example ... suppose we have a BaseTable class with method createTable and EditableTable which extends BaseTable and overrides the createTable method. Now in createTable method of EditableTable we would only create the rows if data was set on the table, and the data is getting set in the super method. So in this scenario we need the super method to be executed first which sets up the basic properties of a table before we create it as a editable table.

I dont know if I could explain what I want to say above :-)

... I think in the above scenario and in other I think its better to invoke the super method first. what do you think ?

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good example, but let's do it vice versa - remove the table. Then you would first need to remove all references to the table before you can remove the table itself. In the end, the dependencies determine the required order, and if there are none you can choose yourself. If there is a choice then the call to super is often placed first, but nothing prevents a user from putting it at the end or even in the middle of the method.

If you can choose it yourself then it is a good thing to have a uniform way within the project, so if you are alone in wanting the super call at the start then I would conform and follow the rest.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic