We are a little inconsistent in our use of setters and getters. I think for
the most part well-written code shouldn't have too many setters and getters
(especially setters) since they expose internal details of the object. But
sometimes you need them. I see three common conventions:

   1. Java-style getXyz() and/or setXyz() method
   2. xyz() plus semantically named setter that describes what it does.
   3. In some newer code I see xyz(x: Option[Int])

There is also a forth option. My understanding of the proper scala idiom
was actually that scala automatically created get and set methods for you,
and the appropriate thing to do is to override these. This is described
here: http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2

Essentially you can start with just

  val xyz = ...

Then later if you want to override the getter you would do

  private val x = ...

  // getter

  def xyz = if(check_something) x else throw new IllegalStateException

Then if you also want to add a setter you do

  private val x = ...

  def xyz = if(check_something) x else throw new IllegalStateException
  def xyz_=(x: Int) {xyz = x}

Let's pick one of these and refactor towards it as we see code that doesn't
match. My vote would be for option 4.

-Jay

Reply via email to