C#’s is
operator and Java’s instanceof
operator allow you to branch on the interface (or, more uncouthly, its base class) an object instance has implemented.
Is it appropriate to use this feature for high level branching based on the capabilities an interface provides?
Or should a base class provide boolean variables to provide an interface to describe the capabilities an object has?
Example:
if (account is IResetsPassword) ((IResetsPassword)account).ResetPassword(); else Print("Not allowed to reset password with this account type!");
vs.
if (account.CanResetPassword) ((IResetsPassword)account).ResetPassword(); else Print("Not allowed to reset password with this account type!");
Are their any pitfalls for using interface implementation for capability identification?
This example was just that, an example. I am wondering about a more general application.