Don’t try to emulate OOP syntax this way. The process
field is abstractly typed, which basically prevents the compiler from doing type inference or inlining anything when you call this function. It’s also not idiomatic Julia style.
(Function-call performance may not matter in this particular example, or in any example where the body of the function takes so much time that everything else is negligible, but it’s a bad habit.)
As I said, the analogue of OOP’s downloader.process()
UFC syntax in Julia is process(downloader)
. i.e. write:
function process(x::UrlDownloader)
# do something
end
function process(x::CsvDownloader)
# do something else
end
function run(downloader::Downloader)
println("Running $(typeof(downloader))")
process(downloader)
end
See also Allowing the object.method(args...) syntax as an alias for method(object, args ...)