In Eclipse, in Android project, if I type something like:
void onCreate(Bundle bundle) {
mButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
handleClick();
});
}
Eclipse then suggests to add handleClick() implementation for me giving me two choices: either in OnClickListener or in the enclosing Activity.
So, if I tell Eclipse to implement handleClick() in the Activity it does so and it makes handleClick() a protected method.
I wonder why not private, what’s the rationale behind that, why it gets protected?
Well, and this is a guess, but a delegate method is a lot more powerful if it’s protected. Being protected allows subclasses to override it, providing an interface for future expansion etc via dynamic dispatch. However, if it’s private, then all you’re accomplishing is moving some code around. You might as well put the content of the method in the body of
onClick