Inheritance

First, recall a previously assigned problem:


tias.java

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

    Wouldn't it be handy if FilledOval had a method to center itself on a location?

         myOval.moveCenterTo( p ); 
    Wouldn't it???!?!?
  • 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