I have the following two methods:
public void informAllFragmentsWhenDatabaseStatusChanged () {
for (int i=0; i<mainActivityPageAdapter.getCount(); i++) {
if (mainActivityPageAdapter.getFragment(i) instanceof InterfaceMainDatabaseStatusChanged)
((InterfaceMainDatabaseStatusChanged) mainActivityPageAdapter.getFragment(i)).onMainDatabaseStatusChanged();
};
}
public void informAllFragmentsWhenListStatusChanged () {
for (int i=0; i<mainActivityPageAdapter.getCount(); i++) {
if (mainActivityPageAdapter.getFragment(i) instanceof InterfaceListStatusChanged)
((InterfaceListStatusChanged) mainActivityPageAdapter.getFragment(i)).onListStatusChanged();
};
}
Please note that each is executed in different moments.
As you noticed main part of both methods is the same. What is different the interface name used by instanceof and method which is executed on object.
The question is how to combine those two methods into one in elegant way.
I was thinking about something like that:
public void informAllFragments (InterfaceType interface);
Any suggestions?