Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
text.gsub("ала", "бала").uppercase
"this is an object".length #=> 17
Обектите не знаят нищо за вътрешното устройство на другите обекти. Единственият начин да взаимодействат с другите е като използват дефинирани външни интерфейси
1965
Стил
Open for extension / closed for modification
stores = []
stores << Store.new(name:"Бакалията", distance: 2.6, price: 28.5)
stores << Store.new(name:"Бай Иван", distance: 2.0, price: 32.0)
stores << Store.new(name:"Супера", distance: 3.2, price: 41.0)
stores << Store.new(name:"Бай Иван", distance: 3.5, price: 22.0)
stores << Store.new(name:"Супера", distance: 5.5, price: 18.0)
Liskov substitution
Single responsibility
Perl
1976
1987
SOLID
Императивен
Функционален
def best_price_nearby (stores)
near = ->(x) { x.distance < 5.0 }
myPrice = ->(x) { x.name == "Бай Иван" ? x.price*0.9 : x.price }
stores.
find_all(&near)\
.collect(&myPrice)\
.min
end
Dependency inversion
def best_price_nearby (stores)
min = stores[0].price
stores.each do |store|
if store.distance < 5.0 then
price = store.price
price = price * 0.9 if store.name == "Бай Иван"
min = price if price < min
end
end
min
end
Interface segregation