James Byrne wrote:

Is this a semantic confusion on my part? Should I consider that what I do with x.exists? is tell the object to answer a question?

Consider...

  if x.exists?
    x.important_method()
  else
    # nothing!
  end

Now lets upgrade the variable x. Sometimes it points to a thing that exists, and sometimes it points to a stub object whose only job is to return 'false' from exists?, and do nothing inside important_method():

  if x.exists?
    x.important_method()
  else
    x.important_method()
  end

Now you can take out the if!

  x.important_method()

We are no longer asking x if it exists. We are telling it what to do, and letting it decide how to do it. That is the heart of OO programming.

(There is still an 'if', somewhere - the one that populates x. But - hopefully - it's only in one place.)

--
  Phlip
  http://www.zeroplayer.com/

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to