Skip to content

Instantly share code, notes, and snippets.

@r7kamura
Last active December 10, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7kamura/4431124 to your computer and use it in GitHub Desktop.
Save r7kamura/4431124 to your computer and use it in GitHub Desktop.

Fat Model

MVCにおけるModel肥大化への対策について

  • moduleへの分割
  • class への分割

moduleへの分割

ビジネスロジックをある単位で分割してmoduleに定義し、modelでincludeする

  • インターフェースは変更されない
  • modelの継承ツリーが複雑化する
  • テストは容易だが、他にincludeされるmoduleとの整合性のテストが必要になる
  • modelのメソッドの名前空間衝突の問題は依然解決されない
  • Prawnはmoduleのincludeを重ねた結果、60個以上ものPublicメソッドを持つようになった

classへの分割

ビジネスロジックをある単位で分割してclassに定義し、これを介してmodelを操作する

  • インターフェースが1層増える
  • 複数のmodelを操作するclassの居場所が出来る
  • テストが容易
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment