Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

real world example of polymorphism

 
Federico Minarelli
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I would like to ask you a question.. Should you be asked "why are oo concepts such as polymorphis, abstraction etc so important? Could you please motivate your answer with a real world example (avoid classical examples like Shapes and Animals, please)?", how would you answer? Can you please point me to some online resources about this please?

Thanks a lot!
Bye!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are shapes not a real-world example? Drawing programs exist.

(I actually worked on a system where we had animals, too, actually, but that was in Lisp/CLOS.)

Can you really not think of any examples where there are types and subtypes?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Federico Carbonetti wrote:Hello!

I would like to ask you a question.. Should you be asked "why are oo concepts such as polymorphis, abstraction etc so important? Could you please motivate your answer with a real world example (avoid classical examples like Shapes and Animals, please)?", how would you answer? Can you please point me to some online resources about this please?

Thanks a lot!
Bye!


How about any program dealing with cars? I'm willing to bet there are going to be times when all you care about is that the object is a car, even if the object being passed is a 1966 Shelby Cobra.
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A real-world example is javax.swing.JComponent. Note that subclasses of that include things like buttons, labels, combo boxes, and so on. All of them have common behaviour which is encapsulated in JComponent and individual behaviour which they control themselves.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic