How can I declare a function in a module for the sole purpose of being extended by users?

Suppose I have such a module

module Foo

abstract type Bar end

function do_something(bar::Bar)
    bar_prepared = prepare(bar)
    "do something"
end

end

My intention for the user is that the user will define a concrete type that is a subtype of Bar and define a function prepare on that concrete type. Then they can call do_something in my module.

Right now, I declare the function by define a dummy function

function prepare()
    return nothing
end

but I am not happy with this. What would be your suggestion?

Define a 0-method function and document how it should be used:

"""
The function `do_something` is supposed to be extended by users in the following way....
"""
function do_something end
5 Likes