the incredible ability to adapt to their environment. Let’s explore together how we can create adaptable, maintainable, and resilient software with some inspiration from nature.
we should stop sending ten arguments to a method end # Get data from the database # Access the fi le system for a certi fi cate template # Generate a new fi le # Save the fi le to S3 # TODO: fi gure out why this is so slow end
initialize(enrollment) @enrollment = enrollment end # Limited interface def title end def subtitle end def date end private # You don't need to know what else is here! end
def initialize(certi fi cate) @certi fi cate = certi fi cate end def render # returns HTML end private # It's a secret end class S3File a tt r_reader :certi fi cate, :html def initialize(certi fi cate, html) @certi fi cate = certi fi cate @html = html end def save # returns the url of the fi le end private # It's a secret end
# Compose our components def generate certi fi cate = Certi fi cate::Base.new(enrolment) html = Certi fi cate::Template.new(certi fi cate).render Certi fi cate::S3File.new(certi fi cate, html).save end # or inject the components def generate(template_strategy, saving_strategy) certi fi cate = Certi fi cate::Base.new(enrolment) html = template_strategy.new(certi fi cate).render saving_strategy.new(certi fi cate, html).save end end end