The principles when applied together intend to create a system
that is easy to maintain and extend over time.
It is typically used with test-driven development,
and is part of an overall strategy of agile and adaptive programming.
The principles when applied together intend to create a system that is easy to maintain and extend over time. that is easy to maintain and extend over time. It is typically used with test-driven development, It is typically used with test-driven development, and is part of an overall strategy of agile and adaptive programming. and is part of an overall strategy of agile and adaptive programming. Wikipedia.org Wikipedia.org
have one, and only one, A class should have one, and only one, reason to change (responsibility) reason to change (responsibility)” ” - Uncle Bob - Uncle Bob “ “do one thing well” - Unix philosophy do one thing well” - Unix philosophy
// input // input def fetch_data def fetch_data end end // process // process def parse def parse End End // ouput // ouput def to_s def to_s End End // store // store def save def save end end end end class class Scraper Scraper include Scraper::Fetchable include Scraper::Fetchable include Scraper::Parsable include Scraper::Parsable include Scraper::Printable include Scraper::Printable Include Scraper::Persistable Include Scraper::Persistable def initialize; end def initialize; end end end
composition' over ' ' over 'class inheritance'. class inheritance'." " (Gang of Four 1995:20) (Gang of Four 1995:20) E.g: Rspec matchers, ActiveRecord validators, … E.g: Rspec matchers, ActiveRecord validators, … class Person class Person Include ActiveModel::Validation Include ActiveModel::Validation validates_with validates_with HasNameValidator HasNameValidator End End RSpec::Matchers RSpec::Matchers.define :be_a_multiple_of do |expected| .define :be_a_multiple_of do |expected| match do |actual| match do |actual| actual % expected == 0 actual % expected == 0 end end end end expect(9).to be_a_multiple_of(3) expect(9).to be_a_multiple_of(3)
.print(self) end end End End class Scraper class Scraper def to_s(printer = def to_s(printer = PrettyPrinter PrettyPrinter) ) printer printer.print(self) .print(self) end end end end
Principles, Patterns, and Practices – Rober C. Martin aka “Uncle Bob” https://speakerdeck.com/plataformatec/rails-solid-by-jose-valim-railsconf-2011 Thank you Happy coding ;-) Thank you Happy coding ;-)