Wednesday, November 29, 2006

OOP 6

I'll try to answer some recent OOP questions here:
  1. You need to check the run-time receiver for the method before looking for the compile-time object which is the super class.
  2. Message resolution uses the run-time type of the receiver.
  3. Flow of control can jump up and down form super to sub-class.
  4. Don't over-code, just rely on polymorphism.
  5. When you override the method's arguments need to agree with prototype.
  6. Java 5 does allow you to change return type on an override as long as it is more specific.
  7. Do you ever really need to use instanceOf?
  8. Class can only have one superclass, but can implement multiple interfaces.
  9. Multiple inheritance is the bain of C++; Java's one superclass + multiple interfaces rules.
  10. Every object derives from Object.
  11. Every object has a toString that derives from Object and can be overriden.
  12. equals is a deep comparison of an object, returns boolean.
  13. If an object is the the same, then there hash code is the same.
  14. Make use of an @Override to tell the compiler your are trying to override a superclass method.
  15. Comparable is just an interface that contains a method int CompareTo(Object o) returns the negative if rcvr/less, 0 if the same, positive if greater.
  16. Java 5 now has Comparable.
  17. You must use encapsulation or you will be lost on more complex projects.
  18. Document your testing strategy.

Chad Salinas