I have the following abstract class:
public abstract class AbstractCreateActionHandler { protected IWorkItem mCurrentWI; public AbstractCreateActionHandler(IWorkItem wi) { this.mCurrentWI = wi; } public final void invoke() { try { if (checkForLockingFile()) { this.executeAction(); Configuration.deleteInstance(); } } catch (IOException e) { Configuration.deleteInstance(); e.printStackTrace(); } } protected abstract void executeAction(); private boolean checkForLockingFile() throws IOException { String path = Configuration.getInstance().getProperty("path"); File lock = new File(path + "lock_"+mCurrentWI.getId()+"__.tmp"); if(!lock.exists()) { lock.createNewFile(); return true; } return false; } }
A subclass of the class extends the abstract class:
public class MyAction extends AbstractCreateActionHandler { public MyAction(IWorkItem wi) { super(wi); } @Override protected void executeAction() {
Question:
Is it possible that a developer who extends an abstract class and implements the executeAction() method does not allow the visibility of executeAction() change?
For now, a developer can simply change the visibility of the method to "public", create a subclass object, and call executeExtion() . The visibility modifier can be changed, and the abstract method is still accepted as "implemented."
Thus, the โnormalโ sequence of calls and checks that are performed in the invoke() abstract class method can be bypassed. Is there any way to check if invoke() method was called?
source share