Yes, this will work in the way that you describe, in that derived classes can choose to implement doSomethingAfterDelete()
or not. However, in Java, all methods of a base class can be overridden by default in the derived class, so you may like to add the final
modifier to your method deleteThisRecord()
to prevent it being overridden:
public final void deleteThisRecord() {
// All standard code goes here
doSomethingAfterDelete(); // call clean up method after successful delete
}