Originally posted by Subhajit Mitra:
how to ensure all child classes will always call a particular implemented function of base class? i don't want to put it in finalize method of base class because i don't want to rely on garbage collector.
Your question is not clear.Could you please explain this in detail.
Framework class implement the same using the following
pattern:
abstract class BaseApollo {
public final
String doMethod(){
String a = myImplementation();
return a;
}
protected abstract String myImplementation(){}
}
// From the framework class
...
...
BaseApollo bApollo = new BaseApolloImpl();//This is a class extended from BaseApollo and myImplementation is concrete.
String returnString = bApollo.doMethod();
This would ensure that myImplementation is called.
You cannot rely on GC as this is not guaranteed , so finalize might never be called.