• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Is polymorphism required only in strongly typed languages?

 
Ranch Hand
Posts: 87
Mac Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm reading up on Polymorphism and the only real advantage I see so far is that because java arrays hold only one type of object, I can store an array of super-class variables holding references to subclasses. I can then treat this array as a controller for those objects.

In PHP it's so easy to treat different objects in the same array or iterative process that I think it's unnecessary - or at least I never came across it.

Is this basically what polymorphism is all about or have I more to learn here?
 
Marshal
Posts: 76854
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are lots more advantages than that.You can have any sort of Animal object secure in the knowledge that it has the makeNoise() method inherited from Animal. You can use each Animal or Dog or Cat or Peke or Lion or Crocodile object and call its makeNoise() method secure in the knowledge that you get the right noise out of it.
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic