I am developing a Provider package in Julia which would be used by multiple Consumer packages. Below is a minimal example of the Project structure for the Provider
package and a sample Consumer package called Consumer_A
to reproduce the issue :
The file generic.jl in the Provider package defines an abstract type AbstractDataLoader
with a function load_data
. This function is overridden in the concrete type CustomDataLoader
defined in the file custom_implementation.jl in the Consumer_A package as shown below:
generic.jl :
export DataProcessor, process_data
abstract type AbstractDataLoader end
function load_data(data_loader::AbstractDataLoader)
error("No load_data function defined for $(typeof(data_loader))")
end
struct DataProcessor end
function process_data(data_loader::AbstractDataLoader)
data = load_data(data_loader)
println("do some processing after loading data: $data")
end
custom_implementation.jl :
import Provider
export CustomDataLoader, load_data
struct CustomDataLoader <: Provider.AbstractDataLoader end
function load_data(data_loader::CustomDataLoader)
return "sample data"
end
The main.jl file has a main
function which instantiates the concrete type and calls a method process_data
that in turn should ideally call the overriding function:
using Provider
export main
function main()
data_loader = CustomDataLoader()
data_processor = DataProcessor()
process_data(data_loader)
end
But instead, on running main()
I get the error "No load_data function defined for CustomDataLoader" that is raised in the generic.jl load_data
function. How do I ensure that the overriding concrete type function gets called in this case?