Last active
August 29, 2015 14:27
-
-
Save amogil/39586f71e135d0836de1 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
module DB | |
def save | |
// .. | |
end | |
end | |
class DbUser | |
include DB | |
def make_move | |
// .. | |
save | |
// .. | |
end | |
--------------- | |
// Ставим польностью новую реализацию DB | |
--------------- | |
class DbUser | |
// Единственное изменение во всех классах-пользователях, заменить include | |
include BrandNewDB | |
end |
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
module DB | |
def save(what) | |
// .. | |
end | |
end | |
class DbUser | |
def make_move | |
// .. | |
DB::save self | |
// .. | |
end | |
end | |
--------------- | |
// Ставим польностью новую реализацию DB | |
--------------- | |
class DbUser | |
def make_move | |
// .. | |
// Попадаем на замену упоминания класса во использованиях по коду во всех классах-пользователях | |
BrandNewDB::save self | |
// .. | |
end | |
end |
Получили то же решение, что и на миксинах, но на один метод больше, нет?
class DbUser
include DB
include User
include SomeOtherShit
def make_move
save # а теперь угадай откуда этот save взялся
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Потому что зависимости надо изолировать: