Created
July 27, 2017 08:25
-
-
Save yakimelon/4accdcfb3013fec0e1d3a22fa4b816a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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