I have a code in Java, where I should call the overriden method from the constructor of base class. I understand that it may cause problems according to many references for example:
Calling an overridden method from a parent class ctor
and also
The question I have which pattern to use instead?
Adding sample code here is a Task constructor:
public <T extends AbstractCommon & IParent> Task(T parent, String uuid, String version, Set<AbstractNode> exceptions) throws Exception {
Event tef = getExecutionFinishedEvent();
Event tep = getExecutionInProgressEvent();
Event tefailed = getExecutionFailed();
Event tefinishedonallnodes = getExecutionFinishedOnAllNodesEvent();
Event tTimeout = getTimeoutEvent();
Event tNotAllNodesAreAcessible = getNotAllNodesAreAccessible();
Event tNotAllObjectsAreAvailable = getNotAllObjectsAreAvailable();
}
Here is the extending class AbstractRemoteTask and there are some others.
public abstract class AbstractRemoteTask extends Task implements InterNodeProcessor {
public AbstractRemoteTask() {
}
@JsonIgnore
@Override
protected Event getExecutionFinishedEvent() {
return getEvent(Event.EventType.EXECUTION_FINISHED_LOCAL);
}
@JsonIgnore
@Override
protected Event getExecutionFinishedOnAllNodesEvent() {
return getEvent(Event.EventType.EXECUTION_FINISHED_ON_ALL_NODES);
}
@Override
protected Event getExecutionInProgressEvent() {
return getEvent(Event.EventType.EXECUTION_IN_PROGRESS);
}
@JsonIgnore
@Override
protected Event getExecutionFailed() {
return getEvent(Event.EventType.EXECUTION_FAILED);
}
@JsonIgnore
@Override
protected Event getTimeoutEvent() {
return new RemoteEvent(this, getNodeUuid(), Event.EventType.TIMEOUT);
}
@JsonIgnore
@Override
protected Event getNotAllNodesAreAccessible() {
return new RemoteEvent(this, getNodeUuid(), Event.EventType.NOT_ALL_NODES_ARE_ACCESSIBLE);
}
@JsonIgnore
@Override
protected Event getNotAllObjectsAreAvailable() {
return new RemoteEvent(this, getNodeUuid(), Event.EventType.NOT_ALL_OBJECTS_ARE_AVAILABLE);
}
So the question is what is the best pattern to implement this? As the way it is implemented is not recommended.