View solid-5-dip-correct-2.rb
# higher level
class Copy
def self.call(reader, writer)
writer.call(reader.call)
end
end
# lower level
Copy.call(WriteToSSD, ReadFromSSD)
View solid-5-dip-correct-1.rb
# higher level
class Copy
def self.call(reader, writer)
writer.call(reader.call)
end
end
# lower level
Copy.call(WriteToHDD, ReadFromHDD)
View solid-5-dip-2.rb
# higher level
class Copy
def self.call
WriteToSSD.call(ReadFromSSD.call)
end
end
# lower level
Copy.call
View solid-5-dip-1.rb
# higher level
class Copy
def self.call
WriteToHDD.call(ReadFromHDD.call)
end
end
# lower level
Copy.call
View solid-3-lsp-fail-use-case.rb
shapes = [ Rectangle.new, Square.new ]
shapes.each { |shape| shape.set_width(100) }
View solid-3-lsp-square-fail.rb
class Square < Rectangle
def set_width(width)
@width = width
@height = height
some_ui_width_related_callbacks
some_ui_height_related_callbacks
end
def set_height(height)
set_width(height)
View solid-3-lsp-correct.rb
class AdminUser
def initialize(settings_array)
settings_from_array(settings_array)
end
# ew. dodatkowo
def settings=(settings_array)
settings_from_array(settings_array)
end
def settings_from_array(settings_array)
View solid-3-lsp-square.rb
class Rectangle
attr_accessor: :width, :height
def set_width(width)
@width = width
some_ui_width_related_callbacks
end
def set_height(height)
@height = height
View solid-3-lsp-fail.rb
class User
def active?
if self.class == User
@settings[:status] == :active
elsif self.class == AdminUser
@settings[1] == :active
end
end
end
View solid-3-lsp.rb
class User
attr_accessor :settings
def active?
@settings[:status] == :active
end
end
class AdminUser < User
end