class TaxRemoteFacadeI've only shown two, but we actually needed the
def state_tax
...
@remote.close
end
def federal_tax
...
@remote.close
end
end
@remote.close code at the end of several methods.Solution: To reduce the duplication you could introduce a mixin with a method to remove the duplication.
module RemoteFacadeThe TaxRemoteFacade can now be defined as the code below.
def remote_call(method_name, &block)
class_eval do
define_method name do
instance_eval &block
@remote.close
end
end
end
end
class TaxRemoteFacade
extend RemoteFacade
remote_call do :state_tax do
...
end
remote_call do :federal_tax do
...
end
end