Skip to content

Instantly share code, notes, and snippets.

@tany3
Created February 27, 2014 07:08
Show Gist options
  • Save tany3/9245701 to your computer and use it in GitHub Desktop.
Save tany3/9245701 to your computer and use it in GitHub Desktop.
仕様を明確にする - Field can be readonly

###仕様を明確にする - Field can be readonly 初期化時だけセットするフィールドはreadonlyにすることで、副作用を防ぐことができる(安全弁になる)。

public class Book
{
  private string readonly name;
  private int readonly ISBN;
  
  public Book(string name, int isbn)
  {
    this.name = name;
    this.ISBN = isbn;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment