Tuesday, February 02, 2016

Thoughts on Sandi Metz presentation

Returning nil in the absence of some object means the type changes. Not all of them are ducks. One of them is going to be NilClass. This will not be able to respond to the message sent by the client.

This problem is because the return type from a method is not uniform. If it always returns an object that can respond to a certain message sent by a client, then the program will not crash.

In Java, we can declare interface. Something like this:

interface OperateCar {
  int turn(direction)
}

You can see that the return type of the turn method is integer. The clients can depend on this fact. They need not worry about handing a null for instance. Since the interface is implicit in Ruby, it allows returning different types of objects, this leads to problems. The only way to make the client code simpler is to make the implementation return something that has consistent interface.

What are the components of an interface?
How can we write code to express the interface ?
Seems like the code will be implicit when it has to express the uniformity or the protocol.
What is a protocol?
What is an interface?