• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 79177
377
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic