Object Oriented Design

Today we’re talking more about invariance. We’re going to talk about invariance in terms of heaps.

We’re also implementing “Turtle Graphics”:

Basically a turtle has a position and a direction on the screen. It can only walk in the direction it’s facing. It can change it’s direction by turning in place. The turtle can save it’s state, and return to its state.

A Turtle may need:

Operations:

public interface TurtleOperations {
	void move(double units);
	void turn(double degrees);
	void save();
	boolean retrieve();
}

There’s a big debate about how to do the turn method. Whether we should degrees, an enum, multiple methods, etc. Now onto implementation:

class Turtle implements TurtleOperations {

}

We got into a huge talk about implementation of direction, and how there are literally an infinite amount of ways to do it properly. To complete this, we use SOLID principles so that:

+---------------------------+          +-----------------------------+
|                           |          |                             |
|                           |          |                             |
|        Interface          |          |          Interface          |
|                           |          |                             |
|    TurtleOperations       <----------+     TracingTurtleOps        |
|                           |          |                             |
|                           |          |                             |
|                           |          |                             |
+------------^--------------+          +----------------^------------+
             |                                          |
             |                                          |
             |                                          |
+---------------------------+          +-----------------------------+
|                           |          |                             |
|                           |          |                             |
|                           |          |                             |
|                           |          |          TracingTurtle      |
|      Turtle               <----------+                             |
|                           |          |                             |
|                           |          |                             |
|                           |          |                             |
+---------------------------+          +-----------------------------+