Skip to content

Instantly share code, notes, and snippets.

@yakimelon
Created July 27, 2017 08:25
Show Gist options
  • Save yakimelon/4accdcfb3013fec0e1d3a22fa4b816a0 to your computer and use it in GitHub Desktop.
Save yakimelon/4accdcfb3013fec0e1d3a22fa4b816a0 to your computer and use it in GitHub Desktop.
# Modelのメソッドでいっぱい分岐するパターン ( メソッドの責務が明確でない )
class Model
def func(x)
if ( x.is_a ) {
# aの処理
} elsif ( x.is_b ) {
# bの処理
}
end
end
class Controller
def main(x)
model = Model.new
model.func(x)
end
end
# Modelのif分岐をメソッドで分けてContorllerで分岐させるパターン ( メソッドの責務は明確だがControllerが肥大化する? )
class Model
def a
# aの処理
end
def b
# bの処理
end
end
class Controller
def main(x)
model = Model.new
if ( x.is_a ) {
model.a
} elseif ( x.is_b ) {
model.b
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment