Created
August 20, 2020 22:19
-
-
Save dearshrewdwit/8e00d2ffcca17c7c8a4aee87a3e7523f 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
# CEO executes a method make_company_efficient. This delegates to COO's method find_company_savings. | |
# The COO's method does a couple of things like sell_old_equipment and reduce_entertainment_budget. | |
# It then calls HRManager's method reduce_payroll. | |
# HRManager's method reduce_payroll iterates through employees and calls employee.fire if employee.performance < 7. | |
# In this example, neither the CEO nor the COO are responsible for firing employees, and both have plausible deniability. | |
# That responsibility has been delegated to the HR Manager, who will have to handle the angry letters herself. | |
class Ceo | |
def initialize(coo = Coo.new) | |
@coo = coo | |
end | |
def make_company_efficient | |
@coo.find_company_savings | |
end | |
end | |
class Coo | |
def initialize(hr_manager) | |
@entertainment_budget = 1000 | |
@hr_manager = hr_manager | |
end | |
def find_company_savings | |
reduce_entertainment_budget | |
@hr_manager.reduce_payroll | |
end | |
private | |
def reduce_entertainment_budget | |
@entertainment_budget -= 200 | |
end | |
end | |
class HrManager | |
def initialize(employees) | |
@employees = employees | |
end | |
def reduce_payroll | |
@employees | |
.select { |employee| employee.performance < 7 } | |
.each(&:fire) | |
end | |
end | |
class Employee | |
def fire | |
@fired = true | |
end | |
def performance | |
rand(1..10) | |
end | |
end | |
employees = [Employee.new, Employee.new] | |
hr_manager = HrManager.new(employees) | |
coo = Coo.new(hr_manager) | |
ceo = Ceo.new(coo) | |
ceo.make_company_efficient |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment