Struct/method definition order advice

I think one possible solution is to define abstract types. For example:

# types.jl

abstract type AbstractMonster end
abstract type AbstractPlayer end

# monster.jl

struct Monster <: AbstractMonster
    ...
end

# player.jl

struct Player <: AbstractPlayer
    ...
end

function capture(player::AbstractPlayer, monster::AbstractMonster)
    ...
end

Then you just have to include types.jl first, and as long as you reference the abstract types in player.jl and monster.jl the order of includes doesn’t really matter between them.

1 Like