Created
April 22, 2019 17:51
-
-
Save omedale/141a590bdeab24612c408acccb939450 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#Violation of the Single Responsibility Principle in Ruby | |
class FinancialReportMailer | |
def initialize(transactions, account) | |
@transactions = transactions | |
@account = account | |
@report = '' | |
end | |
def generate_report | |
@report = "Full Transaction History -> #{@transactions}" | |
end | |
def send_report | |
p "send report #{@report} to #{@account['email']}" | |
end | |
end | |
transactions = [{'name' => 'Femi', 'amount' => 2222}, {'name' => 'Medale', 'amount' => 40000}] | |
account = {'email' => '[email protected]'} | |
mailer = FinancialReportMailer.new(transactions, account) | |
mailer.generate_report | |
mailer.send_report | |
# Correct use of the Single Responsibility Principle in Ruby | |
class FinancialReportMailer | |
def initialize(report, account) | |
@report = report | |
@account = account | |
end | |
def deliver | |
p "send report #{@report} to #{@account['email']}" | |
end | |
end | |
class FinancialReportGenerator | |
def initialize(transactions) | |
@transactions = transactions | |
end | |
def generate | |
"Full Transaction History -> #{@transactions}" | |
end | |
end | |
transactions = [{'name' => 'Femi', 'amount' => 2222}, {'name' => 'Medale', 'amount' => 40000}] | |
account = {'email' => '[email protected]'} | |
report = FinancialReportGenerator.new(transactions).generate | |
FinancialReportMailer.new(report, account).deliver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment