I have two implementations of the WhizBang protocol:
defimpl WhizBang, for: Foo do
do_something_specific(foo) do
# Foo-specific code
end
do_something_common(foo) do
expression1
expression2
etc..
end
end
defimpl WhizBang, for: Bar do
do_something_specific(bar) do
# Bar-specific code
end
do_something_common(bar) do
expression1
expression2
etc..
end
end
Is there a recommended way to factor out the code in do_something_common() so it's not duplicated in the various defimpl's?
Currently my plan is to factor this code out into a common "helper" module and delegate the function call to the helper, eg:
do_something_common(foo_or_bar) do
Helper.do_something_common(foo_or_bar)
end
Or is there a more elegant way?