0

I'm trying to understand why one would use polymorphism in java. All I can think of is that it aids in keeping object types similar for storage. For example the parent class employee could have managers, drivers, cashiers, etc. all stored as one type to avoid using generics. Is this accurate and am I missing another use?

Jacob Ricci
  • 171
  • 7
  • For starters, that sounds like a really insane design; having one model represent more than it should. – Makoto Nov 17 '15 at 15:50
  • Polymorphism is one of the central tenets of object oriented design. A Google search for something like "why use polymorphism" yields *many* results. You've almost kind of sort of talked about one possible example of it, but that is by no means the extent of it. – David Nov 17 '15 at 15:51
  • So what is the purpose of polymorphism then? – Jacob Ricci Nov 17 '15 at 15:51
  • 1
    http://stackoverflow.com/questions/11082640/benefit-of-polymorphism and http://stackoverflow.com/questions/11064409/why-to-use-polymorphism are good to read up on – Makoto Nov 17 '15 at 15:53
  • @JacobRicci: The purpose of polymorphism is to allow one object to be perceived in multiple different forms (types). In your example, a single instance of a `Manager` can be perceived as a `Manager`, as an `Employee`, or as an `Object`, depending on the need of the code acting upon it. – David Nov 17 '15 at 15:59

0 Answers0