Poly morphism - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Poly morphism

Description:

userInput = JOptionPane.showInputDialog('1-sphere 2-cube 3-pyramid 4-Quit' ... or. calc = new Cube( ); 'A subtype may be substituted for a supertype anywhere' ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 6
Provided by: msresearch
Category:
Tags: cube | morphism | poly

less

Transcript and Presenter's Notes

Title: Poly morphism


1
Poly morphism
  • many forms

2
Why is this such a big deal?
  • private IGeometry calc // supertype
  • userInput JOptionPane.showInputDialog("1-sphere
    2-cube 3-pyramid 4-Quit")
  • x Integer.parseInt( userInput )
  • if (x 1)
  • calc new Sphere() // subtype
  • else if (x 2)
  • calc new Cube() // subtype
  • else if (x 3)
  • calc new Pyramid() // subtype
  • else
  • System.exit(0)

3
because
  • the object is chosen in real time
  • it brings along with it, specific methods

4
the methods
  • System.out.println( calc.perimeter() " feet")
  • System.out.println( calc.area() " sq. ft." )
  • System.out.println( calc.volume() " cubic ft."
    )
  • THIS CODE STAYS THE SAME NO MATTER WHICH OBJECT
    IS INSTANTIATED
  • PEOPLE CAN WRITE NEW IGeometry CLASSES AND THEY
    FIT RIGHT IN

5
what makes this possible?
  • private IGeometry calc
  • calc new Sphere( )
  • or
  • calc new Cube( )
  • "A subtype may be substituted for a supertype
    anywhere".
Write a Comment
User Comments (0)
About PowerShow.com