Skip to content

Instantly share code, notes, and snippets.

@kopylovvlad
Created September 16, 2017 15:01
Show Gist options
  • Save kopylovvlad/5311bab442982856f71593a08326c297 to your computer and use it in GitHub Desktop.
Save kopylovvlad/5311bab442982856f71593a08326c297 to your computer and use it in GitHub Desktop.
class SlackLogger
def initialize(message)
@message = message
end
def sending
puts 'we sending message to Slack'
end
end
class EmailLogger
def initialize(message)
@message = message
end
def sending
puts 'we sending message to Email'
end
end
class StorageLogger
def initialize(message)
@message = message
end
def sending
puts 'we sending message to some storage'
end
end
class AbstractLogging
attr_reader :log_string, :logger_factory
def initialize(log_string, logger_factory = nil)
@log_string = log_string
@logger_factory = logger_factory
end
def action
raise 'logger_factory is not implemented' if logger_factory.nil?
logger_factory.new(log_string).sending
end
end
AbstractLogging.new('some error', SlackLogger).action
AbstractLogging.new('some error', EmailLogger).action
AbstractLogging.new('some error', StorageLogger).action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment