Inheritance Basics

Damien Cassou, Stéphane Ducasse and Luc Fabresse http://stephane.ducasse.free.fr

Goal

Pharo treats inheritance the same way as Java

The Basics

  • often we want small adaptations
  • we want to extend existing behavior and state
  • solution: class inheritance
  • a class extends the definition of its superclass

The Basics

a subclass

  • can add state and behavior:
    • color, borderColor, ...
  • can use superclass behavior and state
  • can specialize and redefine superclass behavior

Root of Inheritance Hierarchy

  • Object is the root of most classes
  • ProtoObject (Object's superclass) is for special purposes...
    • ...but we will ignore it as it is not important

The Basics

inheritance is

Inheritance of Instance Variables

  • happens during class definition
  • computed from
    • the class own instance variables
    • the ones of its superclasses

Inheritance of Behavior

  • happens at runtime
  • the method is searched
    • starting from the receiver's class
    • then going to the superclass

Inheritance of Behavior

  • happens at runtime
  • the method is searched
    • starting from the receiver's class
    • then going to the superclass

What You Should Know

/