The responses here are far more interesting than I expected! Thanks!
Re passing the module name – to clarify, you are not passing a string representing the module name, right?
handle_processing(MyApp.VendorOne) # <--- can work with module.process() as desc'd above
# But the following won't work (?)
module_name = "MyApp.VendorOne"
handle_processing(module_name)
The problem, generally speaking, is that the logic that chooses which vendor (i.e. which module) to use must return a string because it is operating on database records and user input etc. So either I have a large case statement somewhere upstream that can specify the actual module names (not as strings), OR I have a large case statement and/or pattern matched functions somewhere downstream that establish the mapping between a string and an actual model name.
In other words, I can force the mapping upstream like this:
case choose_vendor() do:
"vendor-one" -> process_order(VendorOne)
"vendor-two" -> process_order(VendorTwo)
end
And then enjoy a cleaner downstream with def process_order(module), do: module.process()
Or, I have a cleaner upstream, e.g.
choose_vendor() |> process_order() # accepts a string
But then downstream I have to do pattern-matching or a case statement, e.g.
def process_order("vendor-one"), do: VendorOne.process()
def process_order("vendor-two"), do: VendorTwo.process()


















