The example you give seems somewhat reasonable. However, you should not let it crash or return null or something else, but throw an exception if it is invalid. Better yet, use statements.
Using ifs to test object types is not a bad practice, and nothing more than that regarding your classes and relationships. In a statically typed language such as Java, which should not be the norm if (instance b) all the time.
source
share