I have the following code, the purpose of which is, when the method is called for the parent, then it calls the same method for all the children, then this is where the real work was done.
public class Parent {
Child[] children;
public doWork() {
for(int i = 0; i < children.size(); i++)
children.get(i).dowork();
Log.ReportWorkBeingDone(this);
}
}
public class Child extends Parent{
@override
public doWork() {
Log.ReportWorkBeingDone(this);
}
}
Right now, when doWork()
called for the parent, the class Log
receives a method call from Parent
and then once from each of the Child
objects in this array.
Log
? , doWork()
- , Log
, doWork()
Log
?
, , - :
public class Parent {
Child[] children;
public doWork() {
sneakyHiddenWork();
Log.ReportWorkBeingDone(this);
}
protected sneakyHiddenWork(){
for(int i = 0; i < children.size(); i++)
children.get(i).sneakyHiddenWork();
}
}
public class Child extends Parent{
@override
protected sneakyHiddenWork() {
}
}