Don't try to do to much. (Class Relationships). Identify polymorphism in 3 steps. (How to identify polymorphism)?
- find the common operation (e.g. #whatAreYou)
- find how is every operation different and put it in a method in each own class (e.g. #isAString, #isAnInteger, "is nuts")
- introduce an interface for the above classes with that common method
That's all really. Try it with a Calculator example now.
Using polymorphism will
- eliminate the need for multiple if(s)
- eliminate the check for null
- eliminate the exceptional case (in this case to return null)
Plus on each Personality class you get
- final fields
- single responsibility
Disclaimer: This is actual (disguised) code as seen on a very popular API. There are even more problems to discuss about it but let's just focus on one thing at a time.