Comp 110 Classes vs. Instances

Class Instances

  • Classes are essentially blueprints for creating objects
  • In the lecture we were using the Robot class -- The Robot class provided a blueprint to create a robot, such as BB-8.
  • BB-8 was an instance of the Robot class
  • We can create as many instances of the Robot class as we'd like. For example, we could use the Robot class to create another R2-D2. R2-D2 would be another instance of the Robot class.
  • All instances of the same class have the same capabilities of all other instances of that class. If R2-D2 is an instance of the Robot class, and BB-8 is an instance of the Robot class, then we know that both R2-D2 and BB-8 can use the methods (have the capabilities) moveForward and turnRight.
  • All instances of the same class have the same capabilities but they may have different attributes. For example, shape is something that all Robots have, but each instance of a robot may have a different shape. The R2-D2 instance of the Robot class would have cylindrical(ish) as it's shape attribute, while the BB-8 instance of the Robot class would have spherical as it's shape attribute.