next up previous
Next: Example for the design Up: Unit 03 Previous: Example for the design

Example for the design of a class: representation for the objects

We have to decide how to represent the properties of cars. In this case, it is immediate to choose the representation. We represent the objects of the class Car by means of the following instance variables:

Note: In our initial examples, the choice of the representation will always be immediate. However, as we go on with the course, we will see that this step can become significantly more complex.

At this point we are ready to write:

public class Car {
  // representation of the objects
  private String plate;
  private String model;
  private String color;
  private Person owner;

  // public methods realizing the requested functionalities
}


next up previous
Next: Example for the design Up: Unit 03 Previous: Example for the design