Inheritance

First, consider the following class:


tias.java       (quick review 1D array & constructors)

What are our options if we want to include more info with state objects such as two letter postal abbreviation and more?

Approach Pro's Con's
parallel arrays "backward compatible"
  (ie, doesn't break other clients)
A very good thing!
responsibility for keeping indices "matched up"
get source code for State.java & modify to add new instance variables (& methods to access) we know how to do it
  • NOT backward compatible
      (Serious bummer!)
  • Might not have access to source

    It might be handy if our Fish had a method to center itself on a coordinate location.

         finny.moveCenterTo( 50, 150 ); 
  • cut-n-paste a new class with additional instance variables & methods
  • we know how to do it
  • backward compatible   yea!
  • Tedious and repetitive
  • If good stuff gets added to other class; we'll have to keep copying
  • OR..... use INHERITANCE
  • backward compatible   yea!
  • Another learning opportunity!
  • Insight into how all the libraries are built!
  • Syntax to learn and keep straight

    More Notes