InterfaceFunctions.jl provides a robust and flexible (although light and very simple) way to define and manage function interfaces of abstract types in Julia, supporting both obligatory (necessary to implement by the concrete type creator) and optional (ones that provide a default implementation) interfaces with clear error handling and debug logging.
To install InterfaceFunctions.jl, open the Julia REPL and run:
using Pkg
Pkg.add("InterfaceFunctions")There is only a single macro that this package publicly provides: @interface.
Defining interfaces can be simply done by preceding a function (optional interface) or a call (obligatory interface)
by the @interface macro:
using InterfaceFunctions
abstract type AbstractType end
@interface required_function(x::AbstractType)
struct ConcreteType <: AbstractType end
# This will throw an UnimplementedInterface error
try
    required_function(ConcreteType())
catch e
    println(e)
end
# Implement the interface
required_function(x::ConcreteType) = "Hello from ConcreteType!"
println(required_function(ConcreteType())) # Prints "Hello from ConcreteType!"
@interface optional_function(x::AbstractType) = "Hello from AbstractType!"
println(optional_function(ConcreteType())) # Prints "Hello from AbstractType!"For more detailed information, examples, and API reference, please refer to the stable documentation or the development documentation.
All contributions are welcome. For instructions on how to contribute in the correct manner, read the Julia ColPrac collaboration practices guidelines or create a PR and let the maintainers help you out.
See CITATION.bib for the relevant reference(s).
